#===================================================
# Copyright (c) 2006 Continuous Comouting Corp.
# All rights reserved
# XP50 performance test script
# Robert Li 2010-05-03
# Version:1.0.0
# Description:
# Function test
# TODO: determine year automatically
#====================================================
#! /usr/bin/python
import os
import re
import sys
import time
import string
import pexpect
import os.path
import StringIO
import textwrap
import threading
import commands
from pyExcelerator import *

SLOTSN_SEQ = []
SLOTPN_SEQ = []
SLOT_SEQ = []
DEBUG_SLOT_SEQ = []
UNSLOT_SEQ = []

PASS_SLOT_SEQ = []
SLOTFILE_SEQ = []
LOGMSGFILE_SEQ = []





aTestDimmECCRunTime=[0,0,0,0,0,0,0,0,0,0,0,0,0]
aTestDimmECCFailedTime=[0,0,0,0,0,0,0,0,0,0,0,0,0]

aTestSensorTempRunTime=[0,0,0,0,0,0,0,0,0,0,0,0,0]
aTestSensorVoltRunTime=[0,0,0,0,0,0,0,0,0,0,0,0,0]
aTestSensorCurRunTime=[0,0,0,0,0,0,0,0,0,0,0,0,0]
aTestSensorTempFailedTime=[0,0,0,0,0,0,0,0,0,0,0,0,0]
aTestSensorVoltFailedTime=[0,0,0,0,0,0,0,0,0,0,0,0,0]
aTestSensorCurFailedTime=[0,0,0,0,0,0,0,0,0,0,0,0,0]

FAN_MAX_LEVEL    = 15
FAN_MIN_LEVEL    = 6
MAX_FAN_TIMES    = 15
CHASSIS_MAX_SLOT = 2

SHMM_MAX_TMP     = 100
FAN_MAX_NUM      = 2
TEST_MAX_ITEMS   = 5
EXCEL_MAX_ITEMS   = 13

PN_COLOM = 0
SN_COLOM = 1
STARTTIME_COLOM = 2	
ENDTIME_COLOM = 3
TESTSTATUS_COLOM = 4
TESTRES_COLOM  = 5
TIMEINTERVAL_COLOM = 6
V48A_COLOM = 7 		
V48B_COLOM = 8 
HOLDUPCAP_COLOM = 9
CUR48V_COLOM = 10 
PWRTEMP_COLOM = 11
CNODETEMP_COLOM = 12
XLR0TEMP_COLOM =13
XLR0CTEMP_COLOM =14
XLR1TEMP_COLOM =15
XLR1CTEMP_COLOM =16
FM2112TEMP_COLOM =17
FM2112CTEMP_COLOM =18
SHMMTEMP_COLOM = 19
FAN1LEVEL_COLOM = 20
FAN2LEVEL_COLOM =21

XP50_CONFIG_FILE = "/Pkt.cfg"
XP50_STATS_FILE = "/XP50PTStats/xp50"
#=========================================================================
#   Chassis phy solt: 1 2 3 4 5 6 7 8 9 10 11 12 13 
#           FM  slot:
#         Swich Slot:
#=========================================================================
#   FM401 Port 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#   FM402 Port 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#=========================================================================
class VerInputException(Exception):
	'''A user-defined exception class.'''
	def __init__(self, ver_index):
		Exception.__init__(self)
		self.ver_index = ver_index
		
class Test:
	''' Test '''
	def __init__(self, ui):
		self.hCfg = CfgFileProcess()
		self.ui = ui
		global SLOTSN_SEQ
		global SLOTPN_SEQ
		global SLOTFILE_SEQ
		global LOGMSGFILE_SEQ		
		global SLOT_SEQ
		global PASS_SLOT_SEQ		
		SLOT_SEQ = []
		UNSLOT_SEQ = []
		PASS_SLOT_SEQ = []
		for i in range(1,5):
			SLOTSN_SEQ.append(str(i))
			SLOTPN_SEQ.append(str(i))
			SLOTFILE_SEQ.append(" ")
			LOGMSGFILE_SEQ.append(" ")
	def Init_Device(self):
		aTestCom=["XP50COM1","XP50COM2","XP50COM3","XP50COM4","SHMMCOM1","SHMMCOM2"]
		for csStrCom in aTestCom:
			serial_port = self.hCfg.get_test_cfg(csStrCom+"_NAME:")
			if serial_port == "NO_CFG":
				self.ui.info("COM_NAME error")
			else:
				UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)	
				try:
					x = UART.expect(["No such device", "Line in use"],timeout=5)
					if x == 0:
						print "%s No such device " % serial_port 
						sys.stdout.flush()					
						UART.__del__()
					elif x == 1:
						print "%s  device is in use" % serial_port
						sys.stdout.flush()
						csRet=commands.getoutput("ps aux|grep %s"%serial_port)
						print  csRet
						sys.stdout.flush()
						csPid = re.findall("uucp\s+(\d+)\s+0.0\s+0.",csRet)
						print  csPid 
						sys.stdout.flush()
						csRet1=commands.getoutput("kill %s"%csPid[0])
						print  csRet1	
						sys.stdout.flush()
						UART.__del__()						
					else:
						UART.__del__()
				except:
					UART.__del__()
		self.CheckBoard()

	def CheckBoard(self):
		SLOT_SEQ =   []
		UNSLOT_SEQ = []			
		for i in range(1,4+1):
			serial_port = self.hCfg.get_test_cfg("XP50COM"+str(i)+"_NAME:")
			if serial_port == "NO_CFG":
				self.ui.info("COM_NAME error")
			else:
				UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)
				try:
					x = UART.expect(["Connected", "PP50-","(-|\d|)\d+  (-|\d|)\d+  (-|\d|)\d+  (-|\d|)\d+ ","in use"],timeout=5)
					if x == 0:
						x1 = -1
						x1 = self.hCfg.SendCmdSelector(UART,"\r",["pp50","(-|\d|)\d+  (-|\d|)\d+  (-|\d|)\d+  (-|\d|)\d+ ","PP50-"],3,2)
						if x1 == 0 or x1 == 2 or x1 == 3:
							SLOT_SEQ.append(i)				
						else:
							UNSLOT_SEQ.append(i)
						if x1==2 or x1 == 3:
							self.hCfg.SendCmd(UART,"~~.\r","pp50",10,2)							
					elif (x == 1) or (x == 2):
						if self.hCfg.SendCmd(UART,"~~.\r","pp50",10,2)==1:
							SLOT_SEQ.append(i)			
						else:
							UNSLOT_SEQ.append(i)
					elif x == 3:
						UNSLOT_SEQ.append(i)
						UART.__del__()
					else:
						UNSLOT_SEQ.append(i)
				except:
					UNSLOT_SEQ.append(i)
					UART.__del__()
		print SLOT_SEQ
		sys.stdout.flush()		
	def init(self):
		csRet=commands.getoutput(" ifconfig eth0 down")
		print  csRet
		sys.stdout.flush()

		csRet=commands.getoutput("ifconfig eth0 up")
		print  csRet
		sys.stdout.flush()		

		csRet=commands.getoutput("service dhcpd restart")
		print  csRet
		sys.stdout.flush()
		
		csRet=commands.getoutput("service portmap restart")
		print  csRet
		sys.stdout.flush()

		csRet=commands.getoutput("service nfs restart")
		print  csRet
		sys.stdout.flush()

		csRet=commands.getoutput("service iptables stop")
		print  csRet
		sys.stdout.flush()
		
		self.XP501DataStats = DataStats(self.ui,"",1)
		self.XP502DataStats = DataStats(self.ui,"",2)
		self.XP503DataStats = DataStats(self.ui,"",3)
		self.XP504DataStats = DataStats(self.ui,"",4)
		
									 
		if(self.Init_XP50_Test()==1):
			print("Init_XP50_Test() is ok!")
			sys.stdout.flush()
			x = 1
		else:
			x = -1
		if x == -1:
			print("Init_XP50_Test() is fail!")
			sys.stdout.flush()
			return 0			
		print("Init_XP50() is ok!")
		sys.stdout.flush()
		return 1

	def Init_XP50_Test(self):
		global UNSLOT_SEQ
		UNSLOT_SEQ = []
		threadXP501Xlr0 = threading.Thread(target = self.XP501DataStats.Init_XP50Xlr0)
		threadXP501Xlr0.start()

		threadXP502Xlr0 = threading.Thread(target = self.XP502DataStats.Init_XP50Xlr0)
		threadXP502Xlr0.start()			
		threadXP503Xlr0 = threading.Thread(target = self.XP503DataStats.Init_XP50Xlr0)
		threadXP503Xlr0.start()			
		threadXP504Xlr0 = threading.Thread(target = self.XP504DataStats.Init_XP50Xlr0)
		threadXP504Xlr0.start()

		threadXP501Xlr0.join()
		threadXP501Xlr0 = None
		threadXP502Xlr0.join()
		threadXP502Xlr0 = None
		threadXP503Xlr0.join()
		threadXP503Xlr0 = None
		threadXP504Xlr0.join()
		threadXP504Xlr0 = None
		print "Abnormal Slot for the chassis Init_XP50_Test are"
		print UNSLOT_SEQ
		sys.stdout.flush()
		if UNSLOT_SEQ<>[]:
			return 0
		time.sleep(2)

		threadXP501Xlr1 = threading.Thread(target = self.XP501DataStats.Init_XP50Xlr1)
		threadXP501Xlr1.start()
		threadXP502Xlr1 = threading.Thread(target = self.XP502DataStats.Init_XP50Xlr1)
		threadXP502Xlr1.start()
		threadXP503Xlr1 = threading.Thread(target = self.XP503DataStats.Init_XP50Xlr1)
		threadXP503Xlr1.start()
		threadXP504Xlr1 = threading.Thread(target = self.XP504DataStats.Init_XP50Xlr1)
		threadXP504Xlr1.start()						
		threadXP501Xlr1.join()
		threadXP501Xlr1 = None
		threadXP502Xlr1.join()
		threadXP502Xlr1 = None
		threadXP503Xlr1.join()
		threadXP503Xlr1 = None
		threadXP504Xlr1.join()
		threadXP504Xlr1 = None
		print "Abnormal Slot for the chassis Init_XP50_Test are"
		print UNSLOT_SEQ
		sys.stdout.flush()					
		if UNSLOT_SEQ<>[]:
			return 0
		else:  
			return 1
				
	def queryStats(self):
		print "XP50 queryStats :" +time.strftime("%Y-%m-%d %H:%M:%S")
		sys.stdout.flush()
		threadXP501 = threading.Thread(target = self.XP501DataStats.Query_XP50)
		threadXP501.start()
		threadXP502 = threading.Thread(target = self.XP502DataStats.Query_XP50)
		threadXP502.start()			
		threadXP503 = threading.Thread(target = self.XP503DataStats.Query_XP50)
		threadXP503.start()			
		threadXP504 = threading.Thread(target = self.XP504DataStats.Query_XP50)
		threadXP504.start()			
		time.sleep(2)
		threadXP501.join()
		threadXP501 = None
		threadXP502.join()
		threadXP502 = None
		threadXP503.join()
		threadXP503 = None
		threadXP504.join()
		threadXP504 = None
		print "Abnormal Slot for the chassis queryStats are"
		print UNSLOT_SEQ
		sys.stdout.flush()
		if UNSLOT_SEQ<>[]:
			return 0
		else:  
			return 1
		
	def terminrun(self):
		threadXP501 = threading.Thread(target = self.XP501DataStats.End_XP50)
		threadXP501.start()
		threadXP502 = threading.Thread(target = self.XP502DataStats.End_XP50)
		threadXP502.start()			
		threadXP503 = threading.Thread(target = self.XP503DataStats.End_XP50)
		threadXP503.start()			
		threadXP504 = threading.Thread(target = self.XP504DataStats.End_XP50)
		threadXP504.start()				
		time.sleep(2)
		threadXP501.join()
		threadXP501 = None
		threadXP502.join()
		threadXP502 = None
		threadXP503.join()
		threadXP503 = None
		threadXP504.join()
		threadXP504 = None			
		return 1

	def run(self):
		global UNSLOT_SEQ
		UNSLOT_SEQ = []	
		threadXP501 = threading.Thread(target = self.XP501DataStats.Run_XP50)
		threadXP501.start()		
		threadXP502 = threading.Thread(target = self.XP502DataStats.Run_XP50)
		threadXP502.start()			
		threadXP503 = threading.Thread(target = self.XP503DataStats.Run_XP50)
		threadXP503.start()			
		threadXP504 = threading.Thread(target = self.XP504DataStats.Run_XP50)
		threadXP504.start()			
				
		time.sleep(2)
		threadXP501.join()
		threadXP501 = None
		threadXP502.join()
		threadXP502 = None
		threadXP503.join()
		threadXP503 = None
		threadXP504.join()
		threadXP504 = None
		print "Abnormal Slot for the chassis running are"
		print UNSLOT_SEQ
		sys.stdout.flush()
				
		if UNSLOT_SEQ<>[]:
			return 0
		else:  
			return 1
	def end(self):

		threadXP501 = threading.Thread(target = self.XP501DataStats.End_XP50)
		threadXP501.start()
		threadXP502 = threading.Thread(target = self.XP502DataStats.End_XP50)
		threadXP502.start()			
		threadXP503 = threading.Thread(target = self.XP503DataStats.End_XP50)
		threadXP503.start()			
		threadXP504 = threading.Thread(target = self.XP504DataStats.End_XP50)
		threadXP504.start()				
		time.sleep(2)
		threadXP501.join()
		threadXP501 = None
		threadXP502.join()
		threadXP502 = None
		threadXP503.join()
		threadXP503 = None
		threadXP504.join()
		threadXP504 = None			
		print "Abnormal Slot for the chassis running are"
		print UNSLOT_SEQ
		sys.stdout.flush()
		if UNSLOT_SEQ<>[]:
			return 0
		else:  
			return 1
class CfgFileProcess:
	def __init__(self):
		return None	
	def send_scriptFile(self,csFiLename,UART):
		iLine = 0
		iLineBegin = 0
		iLineEnd = 0
		iCmdIndex = 0
		iSubCmdIndex = 0
		iSleepTime = 0
		print " Script path will be   %s " %csFiLename
		sys.stdout.flush()
		try:
			ret_cfg = "NO_FILE"
			csFiLename = self.get_test_cfg("SCRIPT_PATH")+csFiLename
			print " Script path is   %s " %csFiLename
			sys.stdout.flush()
			fh = file(csFiLename,'r+')
			csStr=fh.readline()
			sys.stdout.flush()
			iLine=iLine+1
			csStr.strip()
			#========================================
			#========================================
			if (csStr.find("Begin Line:")<>-1):
				iLineBegin= int(fh.readline())
				iLine=iLine+1
				if (iLineBegin==0) :
					iLineBegin=5
					for  i  in range(1,3):
						csStr=fh.readline()
						iLine=iLine+1
					iLineEnd=32768
				else:
					csStr=fh.readline()								
					iLineEnd= int(fh.readline())
					iLine=iLine+2
					while (iLine<> iLineBegin):
						csStr=fh.readline()
						iLine=iLine+1
			for csStr in fh:
				csStr=csStr.strip()
				iLine=iLine+1
				if (iLine>iLineEnd):
				     break
				if(csStr<>"")and(csStr[0:1]<>"#"):
				    LeftString = csStr[0:4]
				    if (LeftString=="[SLE"):
						csCmd = csStr.split("]")
						iSleepTime=int(csCmd[1])
						for k in range (1,10):
							time.sleep(iSleepTime/20000)
							print "\r Cmd Sleep "+str(k)+" times "
							sys.stdout.flush()							
				    else:
						if (csStr.find("=123456=")<>-1):
							if( csStr[0:4]=="=123"):
								UART.send("\r")
								time.sleep(0.05)
							else:
								csCmd = csStr.split("=123456=")
								if (csStr.find("CTLC")<>-1):
                                    #It will set for the XP50 application that will be 
									UART.sendcontrol('c')
								else:	
									if (csCmd =="BLK"):
										csCmd = " "
									csSendCmd = csCmd[0]+"\r"
									csRet = csCmd[1].strip()
									csRet = csRet.replace("\r","")
									UART.send(csSendCmd)
									if (csRet<>"BLK"):
										try:
											UART.expect(csRet,timeout=30)
											time.sleep(0.05)
											print "\r[S]====>: "+csSendCmd+"\r[R]<====:"+csRet
											print "\r[Ret]<==>:"+UART.before+ UART.after
											sys.stdout.flush()											
										except:
											UART.send(csSendCmd)
											time.sleep(0.05)	
											print "\r[S]====>: "+csSendCmd+"\r[R]<====:"+csRet
											print "\r[Ret]<==>is error resend it"
										        sys.stdout.flush()	
				else:
					time.sleep(0.01)
		except IOError:
			print "Open file error, can't find file: %s" % csFiLename
			sys.stdout.flush()			
			return 0
		return 1

	def get_test_cfg(self, cfg_index):
		#read cfg file
		cfg_index = cfg_index.upper()
		
		try:
			ret_cfg = cfg_index
			csDir = os.path.abspath(os.path.dirname(sys.argv[0]))+XP50_CONFIG_FILE
			fh = file(csDir,"r+")
			for line in fh:
				if cfg_index.find(string.split(line,":")[0])<>-1:
					ret_cfg = string.split(line,":")[1]
					break
			ret_cfg = ret_cfg.replace("\n","")
			ret_cfg.strip()	
			fh.close()
		except IOError:
			ret_cfg = "ERRR1234567RRRROR"
			fh.close()
			csDir = os.path.abspath(os.path.dirname(sys.argv[0]))+XP50_CONFIG_FILE	
			print "expect :Open file error, can't find file: %s" % csDir
			sys.stdout.flush()			  
		return ret_cfg
	def SendCmd(self,UART,csCmd,csRet,itimeout,itimes):
		print "\r[S]====>: "+csCmd+"\r[R]<====:"+csRet
		UART.send(csCmd)
		for i in range(0,itimes+1):
			try:
				itimeoutVal=itimeout+3*i
				UART.expect(csRet,timeout=itimeoutVal)
				try:				
					csUartRet=UART.before+ UART.after
					print "\r[Ret]<==>:"+csUartRet
					if (csUartRet.find("overflow: dropping packet")<>-1):
						UART.send("killall ipmcd;ipmcd;\r")
						time.sleep(2)
						UART.send(csCmd)
					sys.stdout.flush()					
					break
				except:
					csUartRet="SendCmd is fail"
					print "\r[Ret]<==>:"+csUartRet
					sys.stdout.flush()
			except:
				print "send:" + csCmd
				print "except:" + csRet
				print "Retry :" + str(i)
				sys.stdout.flush()
				try:
					UART.expect("overflow: dropping packet",10)
					UART.send("\r")
					csUartRet=UART.before+ UART.after
					if (csUartRet.find("overflow: dropping packet")<>-1):
						UART.send("killall ipmcd;ipmcd;\r")
						time.sleep(2)
					UART.send(csCmd)
					sys.stdout.flush()
				except:					
					if (itimeoutVal>=120):
						UART.send("\r")
					UART.send(csCmd)
		if 	(i==	itimes) :
			print "send:" + csCmd+" except:" + csRet+" is Error!"			
			sys.stdout.flush()
			return 0
		else:
			print "send:" + csCmd+" except:" + csRet+" is ok!"			
			sys.stdout.flush()
			return 1
	def SendCmdSelector(self,UART,csCmd,lcsRet,itimeout,itimes):
		for csRet in lcsRet:
			print "\r[S]====>: "+csCmd+"\r[R]<====:"+csRet
		UART.send(csCmd)
		for i in range(0,itimes):
			try:
				itimeoutVal=itimeout+10*i
				x=UART.expect(lcsRet,timeout=itimeoutVal)
				try:				
					csUartRet=UART.before+ UART.after
				except:
					csUartRet="SendCmd is fail"
				print "\r[Ret]<==>:"+csUartRet
				if (csUartRet.find("overflow: dropping packet")<>-1):
					UART.send("killall ipmcd;ipmcd;\r")
					time.sleep(1)
				UART.send(csCmd)
				sys.stdout.flush()					
				break
			except:
				x=-1
				print "send:" + csCmd
				for csRet in lcsRet:
					print "\r[S]====>: "+csCmd+"\r[R]<====:"+csRet
				print "Retry :" + str(i)
				sys.stdout.flush()
				try:
					UART.expect("overflow: dropping packet",10)
					UART.send("\r")
					try:				
						csUartRet=UART.before+ UART.after
					except:
						csUartRet="SendCmd is fail"
					print "\r[Ret]<==>:"+csUartRet
					if (csUartRet.find("overflow: dropping packet")<>-1):
						UART.send("killall ipmcd;ipmcd;\r")
						time.sleep(1)
					UART.send(csCmd)
					sys.stdout.flush()
				except:					
					if (itimeoutVal>=120):
						UART.send("\r")
					UART.send(csCmd)				
		if 	x==-1:
			print "send:" + csCmd+" except:" + csRet+" is Error!"			
			sys.stdout.flush()
			return x
		else:
			print "send:" + csCmd+" except:" + csRet+" is ok!"			
			sys.stdout.flush()
			return x		
class ExcelObj:
	def __init__(self,csFileName):
		self.hCfg = CfgFileProcess()
		self.Slot1Row = 0
		self.Slot2Row = 0
		self.Slot3Row = 0
		self.Slot4Row = 0
		self.Slot5Row = 0
		self.Slot6Row = 0
		self.Slot7Row = 0
		self.Slot8Row = 0
		self.Slot9Row = 0
		self.Slot10Row = 0		
		self.Slot11Row = 0		
		self.Slot12Row = 0		
		self.Slot13Row = 0		
		self.csStatsFileName = csFileName
		print self.csStatsFileName
		sys.stdout.flush()
		csDir = os.path.abspath(os.path.dirname(sys.argv[0]))
		self.csStatsSaveFileName = self.hCfg.get_test_cfg("XP50_STATS_PATH:")+"PP50"+ time.strftime("%Y-%m-%d_%H-%M-%S")+".xls"
		try:
			SheetsOld = parse_xls(self.csStatsFileName)
		except:
			SheetsOld = parse_xls(self.csStatsFileName)

		SheetOld1 = SheetsOld[0]
		SheetOld2 = SheetsOld[1]
		self.NewBook = Workbook()
		self.ws1 = self.NewBook.add_sheet("Slot1")
		for cs in SheetOld1[1]:
			self.ws1.write(cs[0],cs[1],SheetOld1[1][cs])
			self.Slot1Row=max(cs[0],self.Slot1Row)
		self.ws2 = self.NewBook.add_sheet("Slot2")	
		for cs in SheetOld2[1]:
			self.ws2.write(cs[0],cs[1],SheetOld2[1][cs])
			self.Slot2Row=max(cs[0],self.Slot2Row)

		self.NewBook.save(self.csStatsSaveFileName)
		
	def	getCurrentiRow(self,iSheet):
		if iSheet==1:
			return self.Slot1Row
		if iSheet==2:
			return self.Slot2Row

	def writePN(self,iSheet,iRow,csPN):
		if iSheet==1:
			self.ws1.write(iRow,PN_COLOM,csPN)
		if iSheet==2:	
			self.ws2.write(iRow,PN_COLOM,csPN)
		return 1			
	def writeSN(self,iSheet,iRow,csSN):
		if iSheet==1:
			self.ws1.write(iRow,SN_COLOM,csSN)
		if iSheet==2:	
			self.ws2.write(iRow,SN_COLOM,csSN)
		return 1
		
	def writeStartTime(self,iSheet,iRow,csStartTime):
		if iSheet==1:
			self.ws1.write(iRow,STARTTIME_COLOM,csStartTime)
		if iSheet==2:	
			self.ws2.write(iRow,STARTTIME_COLOM,csStartTime)
		return 1		
	def writeEndTime(self,iSheet,iRow,csEndTime):
		if iSheet==1:
			self.ws1.write(iRow,ENDTIME_COLOM,csEndTime)
		if iSheet==2:	
			self.ws2.write(iRow,ENDTIME_COLOM,csEndTime)
		return 1		
	def writeTestStatus(self,iSheet,iRow,csTestStatus):
		if iSheet==1:
			self.ws1.write(iRow,TESTSTATUS_COLOM,csTestStatus)
		if iSheet==2:	
			self.ws2.write(iRow,TESTSTATUS_COLOM,csTestStatus)
		return 1		
	def writeTestResult(self,iSheet,iRow,csTestResult):
		if iSheet==1:
			self.ws1.write(iRow,TESTRES_COLOM,csTestResult)
		if iSheet==2:	
			self.ws2.write(iRow,TESTRES_COLOM,csTestResult)
		return 1		
	def writeTimeInterval(self,iSheet,iRow,csTimeInterval):
		if iSheet==1:
			self.ws1.write(iRow,TIMEINTERVAL_COLOM,csTimeInterval)
		if iSheet==2:	
			self.ws2.write(iRow,TIMEINTERVAL_COLOM,csTimeInterval)
		return 1		
	def writeVoltage(self,iSheet,iRow,iCol,fVoltage):
		if iSheet==1:
			self.ws1.write(iRow,iCol,fVoltage)
		if iSheet==2:	
			self.ws2.write(iRow,iCol,fVoltage)
		return 1		
	def writeCurrent(self,iSheet,iRow,iCol,fCurrent):
		if iSheet==1:
			self.ws1.write(iRow,iCol,fCurrent)
		if iSheet==2:	
			self.ws2.write(iRow,iCol,fCurrent)
		return 1		
	def writeBoardTemp(self,iSheet,iRow,iCol,fBoardTemp):
		if iSheet==1:
			self.ws1.write(iRow,iCol,fBoardTemp)
		if iSheet==2:	
			self.ws2.write(iRow,iCol,fBoardTemp)
		return 1	
	
	def writeShmmTemp(self,iSheet,iRow,fShmmTemp):
		if iSheet==1:
			self.ws1.write(iRow,SHMMTEMP_COLOM,fShmmTemp)
		if iSheet==2:	
			self.ws2.write(iRow,SHMMTEMP_COLOM,fShmmTemp)
		return 1		

	def writeFan1Level(self,iSheet,iRow,iFanLevel):
		if iSheet==1:
			self.ws1.write(iRow,FAN1LEVEL_COLOM,iFanLevel)
		if iSheet==2:	
			self.ws2.write(iRow,FAN1LEVEL_COLOM,iFanLevel)
		return 1		

	def writeFan2Level(self,iSheet,iRow,iFanLevel):
		if iSheet==1:
			self.ws1.write(iRow,FAN2LEVEL_COLOM,iFanLevel)
		if iSheet==2:	
			self.ws2.write(iRow,FAN2LEVEL_COLOM,iFanLevel)
		self.NewBook.save(self.csStatsSaveFileName)
		return 1		

	def ExcelExit(self):
		self.NewBook.save(self.csStatsSaveFileName)	
		return 1

class ShmmObj:
	def __init__(self,iChassis):
		global SLOT_SEQ
		self.hCfg = CfgFileProcess()
		self.iChassis = iChassis
		self.csTempMin  = str(self.hCfg.get_test_cfg("CONTROL_TEMPMIN:"))
		self.csTempMax  = str(self.hCfg.get_test_cfg("CONTROL_TEMPMAX:"))
		self.iHoldTime = int(self.hCfg.get_test_cfg("CONTROL_SLEEP_TIME"))
		self.iControlSlot = int(self.hCfg.get_test_cfg("CONTROL_SLOT:"))
		self.iInterValue = int(self.hCfg.get_test_cfg("CONTROL_STATS_INTERTIME:"))
		self.lFru=["12","82","84"]
		self.XP50VoltSensorList={'-48V A':3,'-48V B':4,'Holdup Cap':5}
		self.XP50CurrentSensorList={'-48V Current':6}
		self.XP50TempSensorList={'Pwr Module Temp':7,'CNODE Ambient':8,'XLR0 Ambient':10,'XLR0 Core':11,'XLR1 Ambient':14,'XLR1 Core':15,'FM2112 Ambient':17,'FM2112 Core':18}
		self.ShmmTempSensorList={'Local Temp':4}
		self.DicCol={'-48V A':V48A_COLOM,'-48V B':V48B_COLOM,'Holdup Cap':HOLDUPCAP_COLOM,'-48V Current':CUR48V_COLOM,'Pwr Module Temp':PWRTEMP_COLOM,'CNODE Ambient':CNODETEMP_COLOM,'XLR0 Ambient':XLR0TEMP_COLOM,'XLR0 Core':XLR0CTEMP_COLOM,'XLR1 Ambient':XLR1TEMP_COLOM,'XLR1 Core':XLR1CTEMP_COLOM,'FM2112 Ambient':FM2112TEMP_COLOM,'FM2112 Core':FM2112CTEMP_COLOM}
		serial_port = self.hCfg.get_test_cfg("SHMMCOM" +str(self.iChassis)+"_NAME:")	
		self.UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)
		self.iRow=[0,0,0]
		csStatsFileName = self.hCfg.get_test_cfg("XP50_STATS_PATH:")+ "pp50ptbk.xls"
		self.StatsFile = ExcelObj(csStatsFileName)
		for i in [1,2]:
			self.iRow[i]=1
	def ShmmClear(self):
		print "Shmm_clear"
		sys.stdout.flush()
		if self.hCfg.SendCmdSelector(self.UART,"clia alarm clear\r","#",60,3)==0:
			print("clia alarm clear is Error")
			sys.stdout.flush()
		if self.hCfg.SendCmdSelector(self.UART,"clia sel clear\r","#",60,3)==0:
			print("clia sel clear is Error")
			sys.stdout.flush()
			return 0
		else:
			print("Shmm sel clear is ok")		
			sys.stdout.flush()
			return 1
	def ShmmLogin(self):
		print "Shmm_login"
		sys.stdout.flush()
		self.UART.__del__()
		time.sleep(0.5)
		serial_port = self.hCfg.get_test_cfg("SHMMCOM" +str(self.iChassis)+"_NAME:")		
		self.UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)
		print('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)		
		sys.stdout.flush()		
		self.UART.send("\r")		
		x1=self.hCfg.SendCmdSelector(self.UART,"\r",["shmm500 login:","#"],10,2)
		if x1==0:
			if self.hCfg.SendCmd(self.UART,"root\r","word:",10,2)==0:
				print("Shmm login0 is Error")		
				sys.stdout.flush()
				return 0
			if self.hCfg.SendCmd(self.UART,"\r","#",10,3)==0:
				print("Shmm login1 is Error")		
				sys.stdout.flush()
				return 0
			else:
				print("Shmm login1 is ok")		
				sys.stdout.flush()
				return 1
		elif x1==1:		
			print("Shmm login is ok")		
			sys.stdout.flush()
			return 1
		else :							
			print("Shmm login is Error")		
			sys.stdout.flush()
			return 0

	def ShmmFru(self):
		print  "Shmm_fru"
		sys.stdout.flush()

	def ShmmControlFanLevel(self,csFanLevel):
		self.ShmmLogin()
		print  "Shmm_ControlFanLevel:"+csFanLevel
		sys.stdout.flush()
		if self.hCfg.SendCmd(self.UART,"clia minfanlevel "+csFanLevel+"\r","#",10,2)==0:
			print("clia ShmmControlFanLevel is Error")		
			sys.stdout.flush()
			return 0
		else:
			try :
				csRet=self.UART.before+ self.UART.after
			except:
				csRet= "send "+csFanLevel+"is failed!"
			print  csRet
			sys.stdout.flush()
		if self.hCfg.SendCmd(self.UART,"clia setfanlevel all "+csFanLevel+"\r","#",10,2)==0:
			print("clia setfanlevel is Error")		
			sys.stdout.flush()
			return 0
		else:
			try :
				csRet0=self.UART.before+ self.UART.after
			except:
				csRet0= "send "+csSend+"is failed!"
			print  csRet0
			sys.stdout.flush()

	def ShmmLocalTemp(self):	
		self.ShmmLogin()
		csSend = "clia sensordata "+ self.lFru[0]+" "+str(self.ShmmTempSensorList["Local Temp"])
		if self.hCfg.SendCmd(self.UART,csSend+"\r","degrees C",10,2)==0:
			print("clia ShmmLocalTemp is error")		
			sys.stdout.flush()
			return 0
		else:
			try :
				csRet0=self.UART.before+ self.UART.after
			except:
				csRet0= "send "+csSend+"is failed!"
			print  csRet0
			sys.stdout.flush()
		lValue = re.findall("Processed data:\s+(-|\d\d+.\d+)\s+",csRet0)
		if  lValue==[] :
			fShmmTemp=SHMM_MAX_TMP
		else:	
			fShmmTemp=float(lValue[0])
		return fShmmTemp

	def ShmmAllFanLevel(self):
		lcsSend =[ "clia fans","clia fans"]
		iFanLevel=0
		for csSend in lcsSend:
			if self.hCfg.SendCmd(self.UART,csSend+"\r","Maximum Speed Level",30,2)==0:
				print("clia ShmmAllFanLevel is error")		
				sys.stdout.flush()
				return 0
			else:
				try :
					csRet0=self.UART.before+ self.UART.after
				except:
					csRet0= "send "+csSend+"is failed!"
				print  csRet0
				sys.stdout.flush()
			lValue = re.findall("Current Level:\s+(\d+)\s+",csRet0)
			if  lValue==[] :
				iShmmFanLevel=FAN_MAX_LEVEL
			else:
				iShmmFanLevel=int(lValue[0])
			iFanLevel=iFanLevel+iShmmFanLevel
		return 	iFanLevel		

# the Interface for control Shmm localTemp in [csTempMin,csTempMax],and keep csHoldTime 
	def ShmmControlTemp(self,csTempMin,csTempMax):
		print  "Shmm_ControlTemp:[ "+csTempMin+":"+csTempMax+"]"
		sys.stdout.flush()
		for i in range (1,MAX_FAN_TIMES):
			#=========================================	
			fShmmTemp=self.ShmmLocalTemp()
			#=========================================
			iFanLevel=self.ShmmAllFanLevel()/FAN_MAX_NUM
			if (fShmmTemp-float(csTempMax)>=1.00):
				if (iFanLevel<=FAN_MAX_LEVEL):
					self.ShmmControlFanLevel(str(iFanLevel+1))
				else:
					print  "Shmm_ControlFanlevel is beyond of max fanlevel"
					sys.stdout.flush()
			if (float(csTempMin)-fShmmTemp>=1.00):
				if (iFanLevel>=FAN_MIN_LEVEL):
					self.ShmmControlFanLevel(str(iFanLevel-1))
				else:
					print  "Shmm_ControlFanlevel is below of min fanlevel"
					sys.stdout.flush()
			time.sleep(self.iInterValue)

		time.sleep(self.iHoldTime)		

	def ShmmControlPower(self,csSlot,csPowerState):
		print  "Shmm_ControlPower Slot:"+csSlot+" PowerState:"+csPowerState
		sys.stdout.flush()
		
	def ShmmQueryTemp(self):
		global	aTestSensorTempRunTime
		global	aTestSensorTempFailedTime

		self.ShmmLogin()		
		print  "Shmm_QueryTemp Slot:"
		sys.stdout.flush()
		csSend = "clia sensordata "+ self.lFru[0]+" "+str(self.ShmmTempSensorList["Local Temp"])

		if self.hCfg.SendCmd(self.UART,csSend+"\r","degrees C",10,3)==0:
			print("clia ShmmQueryTemp is error")		
			sys.stdout.flush()
			return 0
		else:
			try :
				csRet0=self.UART.before+ self.UART.after
			except:
				csRet0= "send "+csSend+"is failed!"			
			print  csRet0
			sys.stdout.flush()

		lValue = re.findall("Processed data:\s+(-|\d\d+.\d+)\s+",csRet0)
		if  lValue==[] :
			fShmmTemp=-100.0
		else:	
			fShmmTemp=float(lValue[0])			
		for i in [1,2]:
			time.sleep(self.iInterValue)
			aTestSensorTempRunTime[i]=aTestSensorTempRunTime[i]+1
			self.StatsFile.writeShmmTemp(i,self.iRow[i],fShmmTemp)                 
			for csTmp in self.XP50TempSensorList.keys():
				iSensorId=self.XP50TempSensorList[csTmp]
				csSend = "clia sensordata "+ self.lFru[i]+" "+str(iSensorId)
				if self.hCfg.SendCmd(self.UART,csSend+"\r","degrees C",20,2)==0:
					print("clia ShmmQueryTemp is error")		
					sys.stdout.flush()
					return 0
				else:
					try :
						csRet=self.UART.before+ self.UART.after
					except:
						csRet = "send "+csSend+"is failed!"
					print  csRet
					sys.stdout.flush() 
				lValue = re.findall("Processed data:\s+(\d+.\d+)\s+",csRet)                
				try:
					fBoardTemp=float(lValue[0])
				except:
					lValue = re.findall("Processed data:\s+(-\d+.\d+)\s+",csRet)
					try:       
						fBoardTemp=float(lValue[0])
					except:														
						fBoardTemp=-100.0

					if fBoardTemp<=0.0:
						aTestSensorTempFailedTime[i]=aTestSensorTempFailedTime[i]+1	
				self.StatsFile.writeStartTime(i,self.iRow[i],str(time.strftime("%Y-%m-%d %H:%M:%S")))	
				self.StatsFile.writeBoardTemp(i,self.iRow[i],self.DicCol[csTmp],fBoardTemp)
	def ShmmQueryFanLevel(self):
		print  "Shmm_QueryFanLevel Slot:"
		sys.stdout.flush()
		lcsSend =[ "clia fans","clia fans"]
		for csSend in lcsSend:
			if self.hCfg.SendCmd(self.UART,csSend+"\r","Maximum Speed Level",20,2)==0:
				print("clia ShmmQueryFanLevel is error")		
				sys.stdout.flush()
				return 0				
			csRet0=self.UART.before+ self.UART.after
			print  csRet0
			sys.stdout.flush()
			lValue = re.findall("Current Level:\s+(\d+)\s+",csRet0)
			if  lValue==[] :
				iShmmFanLevel=1
			else:
				iShmmFanLevel=float(lValue[0])
			for i in [1,2]:
				if csSend.find(lcsSend[0])<>-1:
					self.StatsFile.writeFan1Level(i,self.iRow[i], iShmmFanLevel)
				if csSend.find(lcsSend[1])<>-1:
					self.StatsFile.writeFan2Level(i,self.iRow[i], iShmmFanLevel)                                              

	def ShmmQueryVolt(self):
		global	aTestSensorVoltRunTime
		global	aTestSensorVoltFailedTime
		print  "Shmm__QueryVolt Slot:"
		sys.stdout.flush()
		for i in [1,2]:
			time.sleep(self.iInterValue)                
			aTestSensorVoltRunTime[i]=aTestSensorVoltRunTime[i]+1
			for csTmp in self.XP50VoltSensorList.keys():
				iSensorId=self.XP50VoltSensorList[csTmp]
				csSend = "clia sensordata "+ self.lFru[i]+" "+str(iSensorId)
				if self.hCfg.SendCmd(self.UART,csSend+"\r","Volts",20,2)==0:
					print("clia ShmmQueryVolt is error")		
					sys.stdout.flush()
					return 0
				else:
					try :
						csRet=self.UART.before+ self.UART.after
					except:
						csRet= "send "+csSend+"is failed!"
					csRet=self.UART.before+ self.UART.after
					print  csRet
					sys.stdout.flush() 
				lValue = re.findall("Processed data:\s+(\d+.\d+)\s+",csRet)                
				try:
					fBoardVolt=float(lValue[0])
				except:
					lValue = re.findall("Processed data:\s+(-\d+.\d+)\s+",csRet)
					try:       
						fBoardVolt=float(lValue[0])
					except:														
						fBoardVolt=-100.0
					if fBoardVolt<=0.0:						
						aTestSensorVoltFailedTime[i]=aTestSensorVoltFailedTime[i]+1						
				self.StatsFile.writeVoltage(i,self.iRow[i],self.DicCol[csTmp],fBoardVolt) 

	def ShmmQueryCurrent(self):
		global	aTestSensorCurRunTime
		global	aTestSensorCurFailedTime
		print  "Shmm__QueryCurrent Slot:"
		sys.stdout.flush()
		for i in [1,2]:
			time.sleep(self.iInterValue)
			aTestSensorCurRunTime[i]=aTestSensorCurRunTime[i]+1
			for csTmp in self.XP50CurrentSensorList.keys():
				iSensorId=self.XP50CurrentSensorList[csTmp]                
				csSend = "clia sensordata "+ self.lFru[i]+" "+str(iSensorId)
				if self.hCfg.SendCmd(self.UART,csSend+"\r","Amps",20,2)==0:
					print("clia ShmmQueryCurrent is error")		
					sys.stdout.flush()
					return 0
				else:
					csRet=self.UART.before+ self.UART.after
					print  csRet
					sys.stdout.flush()   
				lValue = re.findall("Processed data:\s+(\d+.\d+)\s+",csRet)                
				try:
					fBoardCurrent=float(lValue[0])
				except:
					lValue = re.findall("Processed data:\s+(-\d+.\d+)\s+",csRet)
					try:       
						fBoardCurrent=float(lValue[0])
					except:														
						fBoardCurrent=-100.0
					if fBoardCurrent<=0.0:
						aTestSensorCurFailedTime[i]=aTestSensorCurFailedTime[i]+1
				self.StatsFile.writeBoardTemp(i,self.iRow[i],self.DicCol[csTmp],fBoardCurrent)

	def ShmmQueryState(self,csSlot):
		print  "Shmm__QueryState Slot:"+csSlot
		sys.stdout.flush()
		
	def ShmmInit(self):
		global SLOTSN_SEQ
		global SLOTPN_SEQ
		print  "Shmm_Init"
		sys.stdout.flush()
		self.ShmmLogin()
		for i in [1,2]:
			self.StatsFile.writePN(i,self.iRow[i],SLOTPN_SEQ[i+(self.iChassis-1)*2])
			self.StatsFile.writeSN(i,self.iRow[i],SLOTSN_SEQ[i+(self.iChassis-1)*2])
			self.StatsFile.writeStartTime(i,self.iRow[i],str(time.strftime("%Y-%m-%d %H:%M:%S")))
			self.StatsFile.writeTimeInterval(i,self.iRow[i],str(self.iInterValue))
		self.csStartTime = str(time.strftime("%Y-%m-%d %H:%M:%S"))		

	def ShmmRun(self):
		print  "Shmm_Run"
		sys.stdout.flush()
		self.ShmmLogin()
		self.ShmmControlFanLevel(str(FAN_MIN_LEVEL))
		self.ShmmControlTemp(self.csTempMin,self.csTempMax)
		self.ShmmQueryTemp()
		self.ShmmQueryVolt()		
		self.ShmmQueryCurrent()
		self.ShmmQueryFanLevel()
		self.ShmmClear()		
		for i in [1,2]:		
			self.iRow[i] = self.iRow[i] + 1
	def ShmmEnd(self):
		global PASS_SLOT_SEQ
		print  "Shmm_End"
		sys.stdout.flush()
		for i in [1,2]:
			self.StatsFile.writeEndTime(i,self.iRow[i]-1,time.strftime("%Y-%m-%d %H:%M:%S"))
			self.StatsFile.writeTestResult(i,self.iRow[i]-1,"PASS")
		iBoardNum = 0
		self.StatsFile.ExcelExit()
		self.UART.__del__()
class DataStats:
	def __init__(self,ui,csResData,iSlot):
		self.hCfg = CfgFileProcess()
		self.ui = ui
		self.csDataRes = csResData
		self.iSlot = iSlot
	def Init_XP50Xlr0(self):
		global UNSLOT_SEQ
		print("40GbE Slot "+str(self.iSlot)+" Init_XP50"+str(self.iSlot)+"XLR0 initilize start..........")
		sys.stdout.flush()
		csGMAC00IP = self.hCfg.get_test_cfg("GMAC0IP:")+".29.10"+str(self.iSlot)
		csGMAC01IP = self.hCfg.get_test_cfg("GMAC0IP:")+".39.10"+str(self.iSlot)			
		csGMAC0GW = self.hCfg.get_test_cfg("GMAC0IP:")+".0.254"
		csTftpserverIP = self.hCfg.get_test_cfg("TFTPSERVERIP:")
		serial_port = self.hCfg.get_test_cfg("XP50COM"+str(self.iSlot)+"_NAME:")		
		UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)
		UART.send("~~.\r")
		time.sleep(5)		
		UART.send("root\r")
		x1 = self.hCfg.SendCmdSelector(UART,"\r",["XMAC_0_.0.03","cnode-pp50 login","root@cnode-pp50","PP50-","root@localhost","overflow: dropping packet"],1,3)
		print("40GbE Slot "+str(self.iSlot)+" Init_XP50"+str(self.iSlot)+"() ------------------------------------------"+str(x1))
		sys.stdout.flush()		
		if x1 == -1:
			UART.__del__()
			return 0
		if x1 == 5:
			if self.hCfg.SendCmd(UART,"~~.\r","overflow: dropping packet",10,3)==0:
				UART.__del__()
				return 0
			else:
				if self.hCfg.SendCmd(UART,"killall ipmcd;ipmcd;\r","pp50",10,3)==0:
					UART.__del__()
					return 0
				else:
					UART.send("cu -l ttyS2a\r")
		print("40GbE Slot "+str(self.iSlot)+" XP50 IPMC is normal..............")
		sys.stdout.flush()
		UART.__del__()
		UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)
		UART.send("root\r")
		UART.send("\r")		
		x1=self.hCfg.SendCmdSelector(UART,"\r",["XMAC_0_.0.03","cnode-pp50 login","root@cnode-pp50","PP50-","root@localhost"],1,3)
		if x1 == -1:
			UART.__del__()
			return 0
		if x1 == 0:
			if self.hCfg.SendCmd(UART,"~~.\r","root@cnode-pp50",10,3)==0:
				UART.__del__()
				return 0
			else:
				x1=2
		if x1== 1:
			if self.hCfg.SendCmd(UART,"root\r","root@cnode-pp50",10,3)==0:
				UART.__del__()
				return 0
			else:
				x1=2				
		if x1== 2:
			if (self.xp50_test_vlanset(UART)==1):
				print("40GbE Slot "+str(self.iSlot)+" xp50_test_vlanset() setting is ok")
			else:
				print("40GbE Slot "+str(self.iSlot)+" xp50_test_vlanset() is Error")
				sys.stdout.flush()
				UART.__del__()
				return 0
			sys.stdout.flush()
#======================================================
# Adding P/N and S/N information for application
#  
#======================================================
			csPN=self.pp50_get_ccpupn(str(self.iSlot),UART)
			csSN=self.pp50_get_ccpusn(str(self.iSlot),UART)
			print("SLOTPN_SEQ [  "+str(self.iSlot)+" ]= ")
			print SLOTPN_SEQ
			sys.stdout.flush()

			SLOTPN_SEQ[self.iSlot] = csPN
			SLOTSN_SEQ[self.iSlot] = csSN 
			
			UART.__del__()
			UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)
			x2=self.hCfg.SendCmdSelector(UART,"cu -l ttyS2a\r",["XMAC_0_.0.03","cnode-pp50 login","root@cnode-pp50","PP50-","root@localhost"],10,1)
			x2=self.hCfg.SendCmdSelector(UART,"\r",["XMAC_0_.0.03","cnode-pp50 login","root@cnode-pp50","PP50-","root@localhost"],10,5)
			if x2<>-1:
				x1 = x2
			else:
				UART.__del__()
				return 0
		print("40GbE Slot"+str(self.iSlot)+" XP50 Vlan Setting is normal.............."+str(x1))
		sys.stdout.flush()				 
		if x1== 3:
			for i in range(1,4):
				csCmd0="ifconfig -i gmac0 -a "+csGMAC00IP+" -g "+csGMAC0GW+"\r"				
				if self.hCfg.SendCmd(UART,csCmd0,"ipaddr:",60,1)==0:
					print("40GbE Slot "+str(self.iSlot)+" xp50_XLR0 IP setting()  is Failed, checck cable connect status.")
					sys.stdout.flush()
					UART.__del__()
					return 0
				print("40GbE Slot "+str(self.iSlot)+"  xp50_XLR0 IP setting  is  Pass")
				sys.stdout.flush()

				csCmd0="ping "+csTftpserverIP+" \r"
				if self.hCfg.SendCmd(UART,csCmd0,"is alive",60,1)==0:
					UART.send("reboot")			
					try:
						UART.expect(["PP50-0 $"],timeout=180) 
						continue
					except:					
						print("40GbE Slot "+str(self.iSlot)+" xp50_XLR0 IP setting()  is IP Failed, checck cable connect status.")
						sys.stdout.flush()
						return 0
				print("40GbE Slot "+str(self.iSlot)+" xp50_XLR0  ping IP is  Pass")
				sys.stdout.flush()
						

				csCmd0="tftpc -s "+csTftpserverIP+" -f kernel-2.2.7\r"
				UART.send(csCmd0)
				time.sleep(10)						
				print("40GbE Slot "+str(self.iSlot)+" xp50_XLR0  tftpc download is  Pass")
				sys.stdout.flush()
				time.sleep(4)
				csCmd0="elfload\r"
				if self.hCfg.SendCmd(UART,csCmd0,"PP50-0",20,1)==0:
					UART.send("reboot")			
					try:
						UART.expect(["PP50-0 $"],timeout=180) 
						continue
					except:					
						print("40GbE Slot "+str(self.iSlot)+" xp50_XLR0  load image  is Failed, checck cable connect status.")
						sys.stdout.flush()
						return 0
				print("xp50_XLR0 load image is  Pass")
				sys.stdout.flush()
				time.sleep(1)

				csCmd0="userapp xlr_loader\r"
				if self.hCfg.SendCmd(UART,csCmd0,"cpu_online_map=ffffffff, userapp_cpu_map",10,1)==0:
					UART.send("reboot\r")			
					try:
						UART.expect(["PP50-0 $"],timeout=180) 
						continue
					except:					
						print("40GbE Slot "+str(self.iSlot)+" xp50_XLR0 Down load System File is Failed, checck cable connect status.")
						sys.stdout.flush()
						return 0
				print("40GbE Slot "+str(self.iSlot)+" xp50_XLR0 Down load System File is start")
				sys.stdout.flush()
				csHint=""
				for k in  [1,10]:			
					time.sleep(15)
					csHint = csHint+"+"
					print csHint
					sys.stdout.flush()

				if self.hCfg.SendCmd(UART,"\r","localhost login:",20,3)==0:
					UART.send("reboot\r")			
					try:
						UART.expect(["PP50-0 $"],timeout=20) 
						continue
					except:					
						print("40GbE Slot "+str(self.iSlot)+" XP50_XLR0 Down load System File is Failed, checck cable connect status.")
						sys.stdout.flush()
						UNSLOT_SEQ.append(self.iSlot)
						return 0
				else:
					print("40GbE Slot "+str(self.iSlot)+" XP50_XLR0  application  is Pass")
					sys.stdout.flush()
				break

			
			if self.hCfg.SendCmd(UART,"root\r","root@localhost",2,5)==0:
				UART.__del__()
				UNSLOT_SEQ.append(self.iSlot)
				return 0
			x1=4
			print("40GbE Slot "+str(self.iSlot)+" XP50 XLR0 CPU Setting is normal..............")
			sys.stdout.flush()
				
		if x1== 4:
#./.setuprc 10.4.1.29 /opt/rmi/1.6/nfsroot
#ifconfig eth0 10.4.200.30 netmask 255.255.0.0
#mount -o nolock -o tcp 10.4.1.29:/opt/rmi/1.6/nfsroot  /nfsroot
#cd /opt/boot_loader
			for i in range(1,4):
				csCmd0=str("./.setuprc ")+csTftpserverIP+str(" /opt/rmi/1.6/nfsroot \r")				
				if self.hCfg.SendCmd(UART,csCmd0,"root@localhost",120,0)==1:
					UART.send("cd /opt/boot_loader")
					try:
						UART.expect("/opt/boot_loader",timeout=20) 
						break
					except:
						print("40GbE Slot "+str(self.iSlot)+" xp50_XLR0 NFS is Failed, checck cable connect status.")
						sys.stdout.flush()
						UNSLOT_SEQ.append(self.iSlot)
						return 0
				else:
					csRet=commands.getoutput("ifconfig eth0 down")
					print  csRet
					sys.stdout.flush()
					csRet1=commands.getoutput("ifconfig eth0 up")
					print  csRet1	
					sys.stdout.flush()
					continue
				print("40GbE Slot "+str(self.iSlot)+" xp50_XLR0  install nfs service is  Pass")
				sys.stdout.flush()
			UART.__del__()
			UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)
			UART.send("\r")				
			UART.send("\r")			
			x2=self.hCfg.SendCmdSelector(UART,"\r",["XMAC_0_.0.03","cnode-pp50 login","root@cnode-pp50","pp50-","root@localhost"],10,1)
			if x2<>-1:
				x1=x2
			else:
				UART.__del__()
				return 0
			if (x2<>4):
				print "40GbE Slot "+str(self.iSlot)+" Replace  a new XP50 board at 9 Slot! "
				sys.stdout.flush()
				UART.__del__()
				UNSLOT_SEQ.append(self.iSlot)
				return 0
			else:	
				print "40GbE Slot "+str(self.iSlot)+" root@localhost============="
				sys.stdout.flush()				
				if (self.xp50_pkgen_setting(UART)==1):
					print("40GbE Slot "+str(self.iSlot)+" xp50_xlr0_pkgen_setting() setting is ok")
					sys.stdout.flush()
				else:
					print("40GbE Slot "+str(self.iSlot)+" xp50_xlr0_pkgen_setting() is error")
					sys.stdout.flush()
					UART.__del__()
					return 0					
				print("40GbE Slot "+str(self.iSlot)+" xp50_XLR0 packet generator service is  pass")
				sys.stdout.flush()
				for l in range(1,4):
					if self.hCfg.SendCmd(UART,"./userapp load -f ll_pgen_10g -m 0x1fff0 -T virt_uart\r","root@localhost",12,1)==1:
						time.sleep(5)
						UART.send("minicom\r")
						time.sleep(5)
						UART.send("\r")
						if self.hCfg.SendCmd(UART,"\r","XMAC_0_.0.03",10,2)==1:
							x1=0
							print("40GbE Slot "+str(self.iSlot)+" XP50 XLR010GbE Pkt Setting is normal..............")
							sys.stdout.flush()
							break
						else:
							UART.sendcontrol('a')
							time.sleep(1)
							UART.send("x\r")
							UART.send("\r")
							UART.send("\r")
							UART.send("\r")
							if self.hCfg.SendCmd(UART,"./userapp stop -m 0x1fff0\r","None of the specified vcpu is running",10,2)==1:					
								x1=-1															
					time.sleep(5)
				if x1<>0:
					UART.__del__()
					return 0
					
		if x1== 0:
			if self.hCfg.SendCmd(UART,"stop\r","XMAC_0_.0.03",6,3)==0:
				print("40GbE Slot "+str(self.iSlot)+" XLR0 stop is Error")
				sys.stdout.flush()
				UART.__del__()
				return 0            
			print("40GbE Slot "+str(self.iSlot)+" XLR0 stop is ok")
			sys.stdout.flush()	
			time.sleep(1)
			if self.hCfg.SendCmd(UART,"clear\r","XMAC_0_.0.03",6,3)==0:
				print("XLR clear is Error")
				sys.stdout.flush()
				UART.__del__()
				return 0            
			print("XLR0 clear is ok")
			sys.stdout.flush()		
			time.sleep(1)

			if self.hCfg.SendCmd(UART,"race\r","XMAC_0_.0.03",6,3)==0:
				print("40GbE Slot "+str(self.iSlot)+" XLR0 race is Error")
				sys.stdout.flush()
				UART.__del__()
				return 0            
			print("40GbE Slot "+str(self.iSlot)+" XLR0 race is ok")
			sys.stdout.flush()		
			time.sleep(1)
			UART.__del__()

		if (x1<>-1):
			return 1
		else:
			return 0		
	def Init_XP50Xlr1(self):
		global UNSLOT_SEQ		
		print("40GbE Slot "+str(self.iSlot)+" Init_XP50"+str(self.iSlot)+"XLR1 initilize start..........")
		sys.stdout.flush()
		csGMAC00IP = self.hCfg.get_test_cfg("GMAC0IP:")+".29.12"+str(self.iSlot)
		csGMAC01IP = self.hCfg.get_test_cfg("GMAC0IP:")+".39.12"+str(self.iSlot)			
		csGMAC0GW = self.hCfg.get_test_cfg("GMAC0IP:")+".0.254"
		csTftpserverIP = self.hCfg.get_test_cfg("TFTPSERVERIP:")
		
		serial_port = self.hCfg.get_test_cfg("XP50COM"+str(self.iSlot)+"_NAME:")		
		UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)
		UART.send("~~.\r")
		UART.send("cu -l ttyS4a\r")		
		time.sleep(3)
		x1 = self.hCfg.SendCmdSelector(UART,"\r",["XMAC_0_.0.03","cnode-pp50 login","root@cnode-pp50","PP50-","root@localhost","overflow: dropping packet"],1,3)
		print("Init_XP50"+str(self.iSlot)+"() ------------------------------------------"+str(x1))
		sys.stdout.flush()
		
		if x1 == -1:
			UART.__del__()
			UNSLOT_SEQ.append(self.iSlot)
			return 0

		if x1 == 5:
			if self.hCfg.SendCmd(UART,"~~.\r","overflow: dropping packet",10,3)==0:
				UART.__del__()
				UNSLOT_SEQ.append(self.iSlot)
				return 0
			else:
				if self.hCfg.SendCmd(UART,"killall ipmcd;ipmcd;\r","pp50",10,3)==0:
					UART.__del__()
					UNSLOT_SEQ.append(self.iSlot)
					return 0
				else:
					UART.send("cu -l ttyS4a\r")

		print("40GbE Slot "+str(self.iSlot)+" XP50 IPMC is normal..............")
		sys.stdout.flush()
		UART.__del__()
		UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)
		UART.send("root\r")
		UART.send("\r")		
		x1=self.hCfg.SendCmdSelector(UART,"\r",["XMAC_0_.0.03","cnode-pp50 login","root@cnode-pp50","PP50-","root@localhost"],1,3)
		if x1 == -1:
			UART.__del__()
			UNSLOT_SEQ.append(self.iSlot)
			return 0
		if x1 == 0:
			if self.hCfg.SendCmd(UART,"~~.\r","root@cnode-pp50",10,3)==0:
				UART.__del__()
				UNSLOT_SEQ.append(self.iSlot)
				return 0
			else:
				x1=2

		if x1== 1:
			if self.hCfg.SendCmd(UART,"root\r","root@cnode-pp50",10,3)==0:
				UART.__del__()
				UNSLOT_SEQ.append(self.iSlot)
				return 0
			else:
				x1=2
				
		if x1== 2:

			UART.__del__()			
			UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)
			x2=self.hCfg.SendCmdSelector(UART,"cu -l ttyS4a\r",["XMAC_0_.0.03","cnode-pp50 login","root@cnode-pp50","PP50-","root@localhost"],10,1)
			x2=self.hCfg.SendCmdSelector(UART,"\r",["XMAC_0_.0.03","cnode-pp50 login","root@cnode-pp50","PP50-","root@localhost"],10,5)
			if x2<>-1:
				x1 = x2
			else:
				UART.__del__()
				UNSLOT_SEQ.append(self.iSlot)
				return 0
		print("40GbE Slot "+str(self.iSlot)+" XP50_XLR1 Vlan Setting is normal..............")
		sys.stdout.flush()
				
		if x1== 3:
			for i in range(1,4):
				csCmd0="ifconfig -i gmac0 -a "+csGMAC00IP+" -g "+csGMAC0GW+"\r"				
				if self.hCfg.SendCmd(UART,csCmd0,"ipaddr:",60,1)==0:
					print("40GbE Slot "+str(self.iSlot)+" XP50_XLR1 IP setting()  is Failed, checck cable connect status.")
					sys.stdout.flush()
					UART.__del__()
					UNSLOT_SEQ.append(self.iSlot)
					return 0

				print("40GbE Slot "+str(self.iSlot)+" XP50_XLR1 IP setting  is  Pass")
				sys.stdout.flush()
				csCmd0="ping "+csTftpserverIP+" \r"
				if self.hCfg.SendCmd(UART,csCmd0,"is alive",60,1)==0:
					UART.send("reboot\r")			
					try:
						UART.expect(["PP50-1 $"],timeout=180) 
						continue
					except:					
						print("40GbE Slot "+str(self.iSlot)+" xp50_XLR1 IP setting()  is IP Failed, checck cable connect status.")
						sys.stdout.flush()
						UNSLOT_SEQ.append(self.iSlot)
						return 0
				print("40GbE Slot "+str(self.iSlot)+" xp50_XLR1  ping IP is  Pass")
				sys.stdout.flush()
						

				csCmd0="tftpc -s "+csTftpserverIP+" -f kernel-2.2.7\r"
				UART.send(csCmd0)
				time.sleep(10)						
				print("40GbE Slot "+str(self.iSlot)+" xp50_XLR1  tftpc download is  Pass")
				sys.stdout.flush()
				time.sleep(10)
				csCmd0="elfload\r"
				if self.hCfg.SendCmd(UART,csCmd0,"PP50-1",20,1)==0:
					UART.send("reboot")			
					try:
						UART.expect(["PP50-1 $"],timeout=180) 
						continue
					except:					
						print("40GbE Slot "+str(self.iSlot)+" xp50_XLR1  load image  is Failed, checck cable connect status.")
						sys.stdout.flush()
						UNSLOT_SEQ.append(self.iSlot)
						return 0
				print("40GbE Slot "+str(self.iSlot)+" xp50_XLR1 load image is  Pass")
				sys.stdout.flush()
				time.sleep(1)

				csCmd0="userapp xlr_loader\r"
				if self.hCfg.SendCmd(UART,csCmd0,"cpu_online_map=ffffffff, userapp_cpu_map",10,1)==0:
					UART.send("reboot")	
					try:
						UART.expect(["PP50-1 $"],timeout=180) 
						continue
					except:					
						print("40GbE Slot "+str(self.iSlot)+" XP50_XLR1 Down load System File is Failed, checck cable connect status.")
						sys.stdout.flush()
						UNSLOT_SEQ.append(self.iSlot)
						return 0
				print("40GbE Slot "+str(self.iSlot)+" xp50_XLR1 Down load System File is start")
				sys.stdout.flush()
				csHint = ""
				for k in  [1,10]:			
					time.sleep(15)
					csHint = csHint+"+"
					print csHint
					sys.stdout.flush()
										
				if self.hCfg.SendCmd(UART,"\r","localhost login:",20,3)==0:
					UART.send("reboot\r")			
					try:
						UART.expect(["PP50-1 $"],timeout=20) 
						continue
					except:					
						print("40GbE Slot "+str(self.iSlot)+" XP50_XLR1 Down load System File is Failed, checck cable connect status.")
						sys.stdout.flush()
						UNSLOT_SEQ.append(self.iSlot)
						return 0
				else:
					print("40GbE Slot "+str(self.iSlot)+" XP50_XLR1  application  is  Pass")
					sys.stdout.flush()
				break 
		
			if self.hCfg.SendCmd(UART,"root\r","root@localhost",2,5)==0:
				UART.__del__()
				UNSLOT_SEQ.append(self.iSlot)
				return 0
			x1=4
			print("40GbE Slot "+str(self.iSlot)+" XP50 XLR1 CPU Setting is normal..............")
			sys.stdout.flush()
				
		if x1== 4:
			for i in range(1,4):
				UART.send("\r")			
				csCmd0=str("./.setuprc ")+csTftpserverIP+str(" /opt/rmi/1.6/nfsroot \r")				
				if self.hCfg.SendCmd(UART,csCmd0,"root@localhost",120,0)==1:
					UART.send("cd /opt/boot_loader")
					try:
						UART.expect("/opt/boot_loader",timeout=20) 
						break
					except:
						print("40GbE Slot "+str(self.iSlot)+" xp50_XLR1 NFS  is Failed, checck cable connect status.")
						sys.stdout.flush()
						UNSLOT_SEQ.append(self.iSlot)
						return 0
				else:
					csRet=commands.getoutput("ifconfig eth0 down")
					print  csRet
					sys.stdout.flush()
					csRet1=commands.getoutput("ifconfig eth0 up")
					print  csRet1	
					sys.stdout.flush()
					continue

				print("xp50_XLR1  install nfs service is  Pass")
				sys.stdout.flush()
			UART.__del__()
			UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)
			UART.send("\r")				
			UART.send("\r")			
			x2=self.hCfg.SendCmdSelector(UART,"\r",["XMAC_0_.0.03","cnode-pp50 login","root@cnode-pp50","pp50-","root@localhost"],10,1)
			if x2<>-1:
				x1=x2
			else:
				UART.__del__()
				UNSLOT_SEQ.append(self.iSlot)
				return 0
			if (x2<>4):
				print "40GbE Slot "+str(self.iSlot)+" Replace  a new XP50 board at 9 Slot! "
				sys.stdout.flush()
				UART.__del__()
				UNSLOT_SEQ.append(self.iSlot)		
				return 0
			else:	
				print "40GbE Slot "+str(self.iSlot)+" root@localhost============="
				sys.stdout.flush()
				
				if (self.xp50_pkgen_setting(UART)==1):
					print("40GbE Slot "+str(self.iSlot)+" xp50_xlr1_pkgen_setting() setting is ok")
					sys.stdout.flush()
				else:
					print("40GbE Slot "+str(self.iSlot)+" xp50_xlr1_pkgen_setting() is Error")
					sys.stdout.flush()
					UART.__del__()
					UNSLOT_SEQ.append(self.iSlot)
					return 0
				time.sleep(5)					
				print("40GbE Slot "+str(self.iSlot)+" xp50_XLR1 packet generator service is  Pass")
				sys.stdout.flush()
				for l in range(1,4):
					if self.hCfg.SendCmd(UART,"./userapp load -f ll_pgen_10g -m 0x1fff0 -T virt_uart\r","root@localhost",12,1)==1:
						time.sleep(5)
						UART.send("minicom\r")
						time.sleep(5)
						UART.send("\r")
						if self.hCfg.SendCmd(UART,"\r","XMAC_0_.0.03",10,2)==1:
							x1=0
							print("40GbE Slot "+str(self.iSlot)+" XP50 XLR1 10GbE Pkt Setting is normal..............")
							sys.stdout.flush()
							break
						else:
							UART.sendcontrol('a')
							time.sleep(1)
							UART.send("x\r")
							UART.send("\r")
							UART.send("\r")
							UART.send("\r")
							if self.hCfg.SendCmd(UART,"./userapp stop -m 0x1fff0\r","None of the specified vcpu is running",10,2)==1:					
								x1=-1															
					time.sleep(5)

				if x1<>0:
					UART.__del__()
					UNSLOT_SEQ.append(self.iSlot)
					return 0
					
		if x1== 0:
			if self.hCfg.SendCmd(UART,"stop\r","XMAC_0_.0.03",6,3)==0:
				print("40GbE Slot "+str(self.iSlot)+" XLR1 stop is Error")
				sys.stdout.flush()
				UART.__del__()
				UNSLOT_SEQ.append(self.iSlot)
				return 0            
			print("40GbE Slot "+str(self.iSlot)+" XLR1 stop is ok")
			sys.stdout.flush()	
			time.sleep(1)
			if self.hCfg.SendCmd(UART,"clear\r","XMAC_0_.0.03",6,3)==0:
				print("40GbE Slot "+str(self.iSlot)+" XLR1 clear is Error")
				sys.stdout.flush()
				UART.__del__()
				UNSLOT_SEQ.append(self.iSlot)
				return 0            
			print("40GbE Slot "+str(self.iSlot)+" XLR1 clear is ok")
			sys.stdout.flush()		
			time.sleep(1)

			if self.hCfg.SendCmd(UART,"race\r","XMAC_0_.0.03",6,3)==0:
				print("40GbE Slot "+str(self.iSlot)+" XLR1 race is Error")
				sys.stdout.flush()
				UART.__del__()
				UNSLOT_SEQ.append(self.iSlot)
				return 0            
			print("40GbE Slot "+str(self.iSlot)+" XLR1 race is ok")
			sys.stdout.flush()		
			time.sleep(1)
			UART.__del__()

		if (x1<>-1):
			return 1
		else:
			UNSLOT_SEQ.append(self.iSlot)
			return 0
		
	def Run_XP50(self):
		serial_port = self.hCfg.get_test_cfg("XP50COM"+str(self.iSlot)+"_NAME:")		
		for i in range (0,2):
			UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)
			x1 = self.hCfg.SendCmdSelector(UART,"\r",["XMAC_0_.0.03","cnode-pp50 login","root@cnode-pp50","PP50-","root@localhost","overflow: dropping packet"],1,3)
			print("40GbE Slot "+str(self.iSlot)+" Run_XP50"+str(self.iSlot)+"----------XLR"+str(i)+"--------------------------------"+str(x1))
			sys.stdout.flush()
			
			if x1 == -1:
				UART.__del__()
				UNSLOT_SEQ.append(self.iSlot)
				return 0

			if x1 == 5 or x1==2 or x1==0:
				if self.hCfg.SendCmd(UART,"~~.\r","root@cnode-pp50",10,1)==1:
					UART.send("cu -l ttyS"+str((i+1)*2)+"a\r")
					UART.send("\r")
					UART.send("\r")
					x1 = 0
				else:
					if self.hCfg.SendCmd(UART,"killall ipmcd;ipmcd;\r","pp50",10,1)==0:
						print("End_XP50  ipmc "+str(i)+" is failed")
						sys.stdout.flush()											
						UART.__del__()
						UNSLOT_SEQ.append(self.iSlot)
						return 0
			if x1 == 0:
				if self.hCfg.SendCmd(UART,"\r","XMAC_0_.0.03",10,3)==0:
					print "40GbE Slot "+str(self.iSlot)+" Run_XP50 login xp50 "+str(i)+"is Error"
					sys.stdout.flush()            
					UART.__del__()
					return  0
				if self.hCfg.SendCmd(UART,"stop\r","XMAC_0_.0.03",10,3)==0:
					print "40GbE Slot "+str(self.iSlot)+" Run_XP50 login xp50 "+str(i)+"is Error"
					sys.stdout.flush()            
					UART.__del__()
					return  0
				if self.hCfg.SendCmd(UART,"stop\r","XMAC_0_.0.03",10,3)==0:
					print "40GbE Slot "+str(self.iSlot)+" Run_XP50 login xp50 "+str(i)+"is Error"
					sys.stdout.flush()            
					UART.__del__()
					return  0					
				if self.hCfg.SendCmd(UART,"clear\r","XMAC_0_.0.03",10,3)==0:
					print "40GbE Slot "+str(self.iSlot)+" Run_XP50 login xp50 "+str(i)+"is Error"
					sys.stdout.flush()            
					UART.__del__()
					UNSLOT_SEQ.append(self.iSlot)
					return  0
				csPacketSize = self.hCfg.get_test_cfg("PACKETSIZE:")
				if self.hCfg.SendCmd(UART,"length "+str(csPacketSize)+" \r","XMAC_0_.0.03",30,3)==0:
					print "40GbE Slot "+str(self.iSlot)+" Run_XP50 send length xp50 "+str(i)+" is Error"
					sys.stdout.flush()            
					UART.__del__()
					UNSLOT_SEQ.append(self.iSlot)
					return  0
				print("40GbE Slot "+str(self.iSlot)+" XP501 run packet size "+csPacketSize+" Setting is ok")
				sys.stdout.flush()	
				if self.hCfg.SendCmd(UART,"~~.\r","root@cnode-pp50",10,1)==1:
					if self.hCfg.SendCmd(UART,"fswcmd clear stats\r","root@cnode-pp50",10,1)==1:
						time.sleep(2)
						UART.send("cu -l ttyS"+str((i+1)*2)+"a\r")
						UART.send("\r")
						UART.send("\r")
						time.sleep(5)
								
				if self.hCfg.SendCmd(UART,"start\r","XMAC_0_.0.03",10,3)==0:
					print "40GbE Slot "+str(self.iSlot)+" Run_XP50 start xp50 "+str(i)+" is Error"
					sys.stdout.flush()            
					UART.__del__()
					UNSLOT_SEQ.append(self.iSlot)
					return  0
				print("40GbE Slot "+str(self.iSlot)+" Run_XP50 start xp50xlr "+str(i)+" is ok")
				sys.stdout.flush()		
				UART.__del__()

		return  1
	def Query_XP50(self):			
		serial_port = self.hCfg.get_test_cfg("XP50COM"+str(self.iSlot)+"_NAME:")		
		for i in range (0,2):
			UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)
			x1 = self.hCfg.SendCmdSelector(UART,"\r",["XMAC_0_.0.03","cnode-pp50 login","root@cnode-pp50","PP50-","root@localhost","overflow: dropping packet"],1,3)
			print("40GbE Slot "+str(self.iSlot)+" End_XP50 "+str(self.iSlot)+"----------XLR"+str(i)+"--------------------------------"+str(x1))
			sys.stdout.flush()
			
			if x1 == -1:
				UART.__del__()
				UNSLOT_SEQ.append(self.iSlot)
				return 0
			if x1 == 5 or x1==2 or x1==0:
				if self.hCfg.SendCmd(UART,"~~.\r","root@cnode-pp50",10,1)==1:
					if self.hCfg.SendCmd(UART,"fswcmd show stats [1,3,4]\r","root@cnode-pp50",10,1)==1:
						if self.hCfg.SendCmd(UART,"fswcmd show stats [2,5,6]\r","root@cnode-pp50",10,1)==1:
							UART.send("cu -l ttyS"+str((i+1)*2)+"a\r")
							UART.send("\r")
							UART.send("\r")
							time.sleep(5)
							x1 = 0
				else:
					if self.hCfg.SendCmd(UART,"killall ipmcd;ipmcd;\r","pp50",10,1)==0:
						print("40GbE Slot "+str(self.iSlot)+" End_XP50  ipmc "+str(i)+" is failed")
						sys.stdout.flush()											
						UART.__del__()
						UNSLOT_SEQ.append(self.iSlot)
						return 0
			if x1 == 0:
				if self.hCfg.SendCmd(UART,"\r","XMAC_0_.0.03",10,3)==0:
					print "40GbE Slot "+str(self.iSlot)+" End_XP50 login xp50 "+str(i)+"is Error"
					sys.stdout.flush()            
					UART.__del__()
					UNSLOT_SEQ.append(self.iSlot)
					return  0
				if self.hCfg.SendCmd(UART,"race\r","XMAC_0_.0.03",10,3)==0:
					print "40GbE Slot "+str(self.iSlot)+" End_XP50  xp50xlr "+str(i)+" is Error"
					sys.stdout.flush()            
					UART.__del__()
					UNSLOT_SEQ.append(self.iSlot)
					return  0
				print("40GbE Slot "+str(self.iSlot)+" End_XP50  xp50xlr "+str(i)+" is ok")
				sys.stdout.flush()		
				UART.__del__()

		return  1
		

	def End_XP50(self):			
		serial_port = self.hCfg.get_test_cfg("XP50COM"+str(self.iSlot)+"_NAME:")		
		for i in range (0,2):
			UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)
			x1 = self.hCfg.SendCmdSelector(UART,"\r",["XMAC_0_.0.03","cnode-pp50 login","root@cnode-pp50","PP50-","root@localhost","overflow: dropping packet"],1,3)
			print("40GbE Slot "+str(self.iSlot)+" End_XP50 "+str(self.iSlot)+"----------XLR"+str(i)+"--------------------------------"+str(x1))
			sys.stdout.flush()
			
			if x1 == -1:
				UART.__del__()
				UNSLOT_SEQ.append(self.iSlot)
				return 0

			if x1 == 5 or x1==2 or x1==0:
				if self.hCfg.SendCmd(UART,"~~.\r","root@cnode-pp50",10,1)==1:
					UART.send("cu -l ttyS"+str((i+1)*2)+"a\r")
					UART.send("\r")
					UART.send("\r")
					time.sleep(5)
					x1 = 0
				else:
					if self.hCfg.SendCmd(UART,"killall ipmcd;ipmcd;\r","pp50",10,1)==0:
						print("40GbE Slot "+str(self.iSlot)+" End_XP50  ipmc "+str(i)+" is failed")
						sys.stdout.flush()											
						UART.__del__()
						UNSLOT_SEQ.append(self.iSlot)
						return 0
			if x1 == 0:
				if self.hCfg.SendCmd(UART,"\r","XMAC_0_.0.03",10,3)==0:
					print "40GbE Slot "+str(self.iSlot)+" End_XP50 login xp50 "+str(i)+"is Error"
					sys.stdout.flush()            
					UART.__del__()
					return  0
				if self.hCfg.SendCmd(UART,"stop\r","XMAC_0_.0.03",10,3)==0:
					print "40GbE Slot "+str(self.iSlot)+" Run_XP50 login xp50 "+str(i)+"is Error"
					sys.stdout.flush()            
					UART.__del__()
					return  0					
				if self.hCfg.SendCmd(UART,"stop\r","XMAC_0_.0.03",10,3)==0:
					print "40GbE Slot "+str(self.iSlot)+" End_XP50  xp50xlr "+str(i)+" is Error"
					sys.stdout.flush()            
					UART.__del__()
					UNSLOT_SEQ.append(self.iSlot)
					return  0
				print("40GbE Slot "+str(self.iSlot)+" End_XP50  xp50xlr "+str(i)+" is ok")
				sys.stdout.flush()		
				UART.__del__()

		return  1

			
		
			
	def Init_SystemDevice(self,iSlot):
		serial_port = self.hCfg.get_test_cfg("XP50COM"+str(iSlot)+"_NAME:")
		UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)
		UART.sendcontrol("c")
		UART.sendcontrol("c")
		UART.__del__()
		UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)	
		try:
			x = UART.expect(["No such device", "Line in use"],timeout=1)
			if x == 0:
				print "%s No such device " % serial_port 
				sys.stdout.flush()					
			elif x == 1:
				print "%s  device is in use" % serial_port
				sys.stdout.flush()
				csRet=commands.getoutput("ps aux|grep %s"%serial_port)
				print  csRet
				sys.stdout.flush()
				csPid = re.findall("uucp\s+(\d+)\s+\d.\d\s+\d.",csRet)
				print  csPid 
				sys.stdout.flush()
				csRet1=commands.getoutput("kill %s"%csPid[0])
				print  csRet1	
				time.sleep(0.5)
				sys.stdout.flush()
			else:
				UART.__del__()
		except:
			UART.__del__()		
		UART.__del__()
	def	Reset_XP50(self,UART):
		x=self.hCfg.SendCmdSelector(UART,"~~.\r",["root@cnode-pp50","login"],10,2)
		if x==1:
			if self.hCfg.SendCmd(UART,"root\r","root@cnode-pp50",10,2)==1:			
				print "reset  pp50 slot.........login is ok"
				sys.stdout.flush()
			else:
				print "reset  pp50 slot.........login is error"
				sys.stdout.flush()            
				return 0
		elif x==0:
			print "reset  pp50 slot.........login is ok"
			sys.stdout.flush()
		else:
			print "reset  pp50 slot.........login is error"
			sys.stdout.flush()            
			return 0		
		self.hCfg.SendCmd(UART,"reboot\r","umount",40,2)
		print "reset  pp50 slot.....reboot....Start"
		sys.stdout.flush()
		csHint = ""		
		for k in  [1,10]:		
			time.sleep(15)
			csHint = csHint+"+"
			print csHint
			sys.stdout.flush()

		for i in range (0,20):
			time.sleep(2)
			if self.hCfg.SendCmd(UART,"root\r","root@cnode-pp50",2,2)==1:
				break
			else:
				csProcess= "reset  pp50 slot.......runing  " +  str(i*2)
				print  csProcess
				sys.stdout.flush()
		if i>=49:
			return 0
		print "reset  pp50 slot.......end"		
		sys.stdout.flush()		
		for i in range (0,100):
			time.sleep(3)
			csProcess=" pp50 slot.....cpu....down... " +  str(i*1)
			print  csProcess
			sys.stdout.flush()
			if self.hCfg.SendCmd(UART,"halcmd\r","uv",1,2)<>1:
				csProcess= " pp50 slot ..cpu...is ..up"
				print csProcess
				sys.stdout.flush()
				break
		lcmd=["cu -l ttyS2a","cu -l ttyS4a"]
		for j in range(0,2):
			print "reset  pp50 slot........cpu......Start"
			for i in range (0,50):
				time.sleep(1)
				csProcess="time " +str(j)+" pp50 slot.....cpu....runing  " +  str(i*2)
				print  csProcess
				sys.stdout.flush()
				if self.hCfg.SendCmd(UART,lcmd[j]+"\r","XP50-",1,2)==1:
					csProcess= "time " +str(j)+" pp50 slot ..cpu.....end"
					print csProcess
					sys.stdout.flush()
					break
		
		self.hCfg.SendCmd(UART,"~~.\r","root@cnode-pp50",2,1)
		self.hCfg.SendCmd(UART,"~~.\r","root@cnode-pp50",2,1)		
		return 1

	def	ReloadVlan_XP50(self,UART):
		if self.hCfg.SendCmd(UART,"fswcmd reload config /etc/fswitchCfg.def\r","root@cnode-pp50",120,3)==1:        
			print"ReloadVlan_XP50 return is ok!"
			sys.stdout.flush()	
		else:
			print"ReloadVlan_XP50 return is error!"
			sys.stdout.flush()
			return 0
		time.sleep(60)
		for i in range(0,30):
			if(self.pp50_check_vlanset(UART,-1)<>-1):
				break
			else:
				print"Wait for ReloadVlan XP50 ........."
				sys.stdout.flush()
		return 1					
	def	DisablePort_XP50(self,UART):
		if self.hCfg.SendCmd(UART,"fswcmd disable port all\r","root@cnode-pp50",120,3)==1:        
			print"DisablePort_XP50 return is ok!"
			sys.stdout.flush()
			return 1				
		else:
			print"DisablePort_XP50 return is error!"
			sys.stdout.flush()
			return 0
	def	EnablePort_XP50(self,UART):
		if self.hCfg.SendCmd(UART,"fswcmd enable port all\r","root@cnode-pp50",120,3)==1:        
			print"EnablePort_XP50 return is ok!"
			sys.stdout.flush()
			return 1				
		else:
			print"EnablePort_XP50 return is error!"
			sys.stdout.flush()
			return 0

	def XP50ClearLogMsgFile(self,UART):
		UART.send("echo "">/var/log/messages \r")
		try:
			UART.expect("root@cnode-pp50:~",timeout=60)			
		except:
			UART.send("echo "">/var/log/messages \r")
			
		try:
			self.csLogMsgData = UART.before + UART.after
		except:
			self.csLogMsgData = "XP50ClearLogMsgFile is error"
		print  self.csLogMsgData
		sys.stdout.flush()
		time.sleep(0.5)
		return 	 1
	def GetLogMsgFile(self,UART):
		UART.send("cat /var/log/messages \r")
		try:
			UART.expect("root@cnode-pp50:~",timeout=100)
		except:
			UART.send("cat /var/log/messages \r")
		self.csLogMsgData = UART.before + UART.after
		print  self.csLogMsgData
		sys.stdout.flush()
		return 	 self.csLogMsgData
	def SaveLogMsgFile(self):
		global LOGMSGFILE_SEQ
		serial_port = self.hCfg.get_test_cfg("XP50COM"+str(self.iSlot)+"_NAME:")
		print "open Serial port  %s ...." %serial_port
		sys.stdout.flush()						
		UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)
		UART.send("~~.\r")
		if (self.pp50_ipmc_login(UART)==1):
			print("pp50_ipmc_login() setting is ok")
		else:
			print("pp50_ipmc_login()  is error")
			sys.stdout.flush()
			UART.__del__()			
			return 0
		sys.stdout.flush()
		UART.__del__()
		UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)
		csSave =  self.GetLogMsgFile(UART)
		XP50_LOGMSG_FILE = LOGMSGFILE_SEQ[self.iSlot]
		logmsgFile=open(XP50_LOGMSG_FILE,"a")
		logmsgFile.write(csSave)
		logmsgFile.close()			
		return 1		
	def DataStatsAlarm(self,iPid):
		return 1
		
	def pp50_enter_ipmc(self,UART):
		# root@cnode-pp50:~
		##self.ui.info("pp50_enter_ipmc")
		self.hCfg.SendCmd(UART,"root\r","root@cnode-pp50",10,3)
		x=self.hCfg.SendCmdSelector(UART,"\r",["cnode-pp50 login","root@cnode-pp50","=>"],10,3)
		if x==-1:
			print "pp50_enter_ipmc is error!" 
			sys.stdout.flush()
			return 0		
		elif x == 0:
			self.hCfg.SendCmd(UART,"root\r","root@cnode-pp50",10,3)
		elif x == 1:
			time.sleep(0.001)
			#self.ui.info("Enter ipmc....done")
		elif x == 2:
			self.hCfg.SendCmd(UART,"reset\r","cnode-pp50 login",300,2)
			if self.hCfg.SendCmd(UART,"root\r","root@cnode-pp50:",6,2)==1:
				print "pp50_enter_ipmc is ok!" 
				sys.stdout.flush()		
				return 1
		else :
			return 0
		print "pp50_enter_ipmc is ok!" 
		sys.stdout.flush()		
		return 1

	def pp50_ipmc_login(self,UART):
		#self.ui.info("pp50_ipmc_login")
		print  "pp50_ipmc_login start"
		sys.stdout.flush()
		UART.send("~~.\r")
		UART.send("root\r")
		if(self.pp50_enter_ipmc(UART)==1):
			return 1
		else:
			return 0
	def pp50_get_PN(self,UART):
		#self.ui.info("pp50_get_Pn")
		csScriptPath= self.hCfg.get_test_cfg("pp50_get_PN")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0
	def pp50_get_SN(self,UART):
		#self.ui.info("pp50_get_Sn ")
		csScriptPath= self.hCfg.get_test_cfg("pp50_get_SN")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0
	def pp50_get_bdinfo(self,csSlot):	
		serial_port = self.hCfg.get_test_cfg("XP50COM"+csSlot+"_NAME:")
		print "open Serial port  %s ...." %serial_port
		sys.stdout.flush()	
		UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)
		if (self.pp50_ipmc_login(UART)==1):			
			print("pp50_ipmc_login() setting is ok")
		else:
			if (self.pp50_ipmc_login(UART)==1):			
				print("pp50_ipmc_login() setting is ok")
			else:
				print("pp50_ipmc_login()  is error")
				sys.stdout.flush()				
				return "Error"
		sys.stdout.flush()
		
		UART.__del__()			
		UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)
		if self.hCfg.SendCmd(UART,"cnodekv -f 0 -c3 -m \r","root@cnode-pp50:",120,3)==1:
			csRet = UART.before+ UART.after
		else:
			csRet = "Error"			
		print csRet
		sys.stdout.flush()
		UART.__del__()	
		return csRet
	def pp50_get_ServiceInfor(self,csSlot,csCmd,csExp):
		print "Serive Information Test Slot: ===" + csSlot+"==="
		serial_port = self.hCfg.get_test_cfg("XP50COM"+csSlot+"_NAME:")
		print "open Serial port  %s ...." %serial_port
		sys.stdout.flush()					
		UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)
		if (self.pp50_ipmc_login(UART)==1):
			print("slot:"+csSlot+" pp50_ipmc_login() setting is ok")
		else:
			if (self.pp50_ipmc_login(UART)==1):
				print("slot:"+csSlot+" pp50_ipmc_login() setting is ok")
			else:
				if (self.pp50_ipmc_login(UART)==1):	
					print("slot:"+csSlot+" pp50_ipmc_login() setting is ok")			
				else:	
					print("slot:"+csSlot+" pp50_ipmc_login()  is Error")
					sys.stdout.flush()				
					UART.__del__()
					return "Error"
		sys.stdout.flush()
		try:
			UART.__del__()
		except:
			print("slot:"+csSlot+" pp50_ipmc_login()  is error for del UART")
			sys.stdout.flush()				
			
		UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop\r'%serial_port)		
		if self.hCfg.SendCmd(UART,csCmd,csExp,120,3)==1:			
			csRet= UART.before+ UART.after
			print  "pp50_get_ServiceInfor====:"+csRet
			sys.stdout.flush()			
			if (csRet.find("FM_")==-1):
				print  "pp50_get_ServiceInfor csRet  ==="+csSlot+"===is error==="
				sys.stdout.flush()
				UART.__del__()			
				return "pp50_get_ServiceInfor Error"
			else:
				print  "pp50_get_ServiceInfor csRet ===="+csSlot+"===is ok====="
				sys.stdout.flush()				
				UART.__del__()
				return csRet
		else:
			print  "XP50  info Slot:==="+csSlot+"===information is error====="
			sys.stdout.flush()				
			UART.__del__()
			return csRet

		
		
	def pp50_get_ccpupn(self,csSlot,UART):
		csRet=" "
		self.hCfg.SendCmd(UART,"root\r","root@cnode-pp50",10,3)		
		if self.hCfg.SendCmd(UART,"cnodekv -f 0 -c3 -m brd_part\r","\d{1}-\w{5}",60,3)==1:			
			csRet = UART.before+ UART.after
			print  "pp50_get_ccpupn:"+csRet
			sys.stdout.flush()
			csPid = re.findall("\d{1}-\w{5}",csRet)
			print  csPid 
			sys.stdout.flush()
			csRet =csPid[0]
			print  "pp50_get_ccpupn...0000...+++"+csSlot+":"+csRet
			sys.stdout.flush()	
			if (csRet.find('0-')<>-1):
				return csRet
		else:
			print  "pp50_get_ccpupn Slot:==="+csSlot+"===information is error==="
			sys.stdout.flush()				
			return "Error"
	def pp50_get_ccpusn(self,csSlot,UART):
		csRet=" "
		self.hCfg.SendCmd(UART,"root\r","root@cnode-pp50",10,3)	
		if self.hCfg.SendCmd(UART,"cnodekv -f 0 -c3 -m brd_ser_num\r","\w{3}-\w{5}",20,5)==1:
			csRet = UART.before+ UART.after
			print  "pp50_get_ccpusn:"+csRet
			sys.stdout.flush()
			csPid = re.findall("\w{3}-\w{5}",csRet)
			print  csPid 
			sys.stdout.flush()
			csRet =csPid[0]
			print  "pp50_get_ccpusn...0000...+++"+csSlot+":"+csRet
			sys.stdout.flush()
			if (csRet.find('-')<>-1):
				return csRet
			else:
				return "Error"
		else:
			print  "XP50  pp50_get_ccpusn Slot:==="+csSlot+"===information is Error==="
			sys.stdout.flush()
			return csRet			

	def pp50_ipmc_logout(self,UART):
		try:
			self.hCfg.SendCmd(UART,"root\r","root@cnode-pp50",10,3)	
		except:
			return 0
		return 1

	def pp50_test_Tahoestats(self,UART):
		csScriptPath= self.hCfg.get_test_cfg("pp50_test_Tahoestats")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0
	def pp50_test_Balistats(self,UART):
		csScriptPath= self.hCfg.get_test_cfg("pp50_test_Balistats")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0
	def pp50_enable_port(self,UART):
		#self.ui.info("pp50_enable_port")
		csScriptPath= self.hCfg.get_test_cfg("pp50_enable_port")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0
	def pp50_set_cop50rtm(self,UART):
		csScriptPath= self.hCfg.get_test_cfg("pp50_set_cop50rtm")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0
	def pp50_del_cop50rtm(self,UART):
		csScriptPath= self.hCfg.get_test_cfg("pp50_del_cop50rtm")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0


	def pp50_enable_allport(self,UART):
		#self.ui.info("pp50_enable_allport")
		csScriptPath= self.hCfg.get_test_cfg("pp50_enable_allport")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0
	def pp50_disable_port(self,UART):
		#self.ui.info("pp50_disable_port")
		csScriptPath= self.hCfg.get_test_cfg("pp50_disable_port")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0
	def pp50_disable_geport(self,UART):
		#self.ui.info("pp50_disable_geport")
		csScriptPath= self.hCfg.get_test_cfg("pp50_disable_geport")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0		
	def pp50_disable_allport(self,UART):
		#self.ui.info("pp50_disable_allport")
		csScriptPath= self.hCfg.get_test_cfg("pp50_disable_allport")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0
	def pp50_test_portmode(self,UART,iMode):
		self.hCfg.SendCmd(UART,"root\r","root@cnode-pp50",10,3)			
		UART.sendline("fswcmd set port store-forward all "+str(iMode))
		# set port store-forward {<port> <port label> | all} <value>		
		try:
			UART.expect("root@cnode-pp50:~",timeout=10)	
			try:
				csRet = UART.before+UART.after
			except:
				csRet = "pp50_test_portmode try it fail "			
		except:
			UART.sendline("fswcmd set port store-forward all "+str(iMode))			
#			UART.expect("root@cnode-pp50:~",timeout=30)
			try :
				csRet = UART.before+UART.after
			except:
				csRet = "pp50_test_portmode has tried 2 times."
			print  "pp50_test_portmode expect is failed ......++++++"+csRet
			sys.stdout.flush()
			return 0
		print csRet
		sys.stdout.flush()
		return 1

	def pp50_test_clrstats(self,UART):
		#self.ui.info("pp50_test_clrstats ")
		UART.send("fswcmd clear stats\r")
		csScriptPath= self.hCfg.get_test_cfg("pp50_test_clrstats")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0
	def pp50_check_vlanset(self,UART,iType):
		if (iType==-1):
			test = 1
			for i in range(0,50):
				self.hCfg.SendCmd(UART,"fswcmd show vlan \r","root@cnode-pp50",10,3)
				try:
					csRet = UART.before+UART.after
				except:
					csRet = "show vlan  9 try it fail "
					test = -1				
				if (csRet.find('synchronizing the configuration')<>-1) or  (csRet.find('Info:')<>-1):
					test = -1
				else:
					test =  1
				if (test == -1):
					time.sleep(4)
				else:
					break
			return test
#========================			
#
#
#========================
		else:
			return 1
		
		if (iType==0):
			result = 1
			result9 = 1
			self.hCfg.SendCmd(UART,"fswcmd show vlan  9\r","root@cnode-pp50:",10,3)
			try:
				csRet = UART.before+UART.after
			except:
				csRet = "show vlan  9 try it fail "
				result9 = -1
			print  "UART.before+UART.after:====:"+csRet
			sys.stdout.flush()
			if (csRet.find('RTMXG1')==-1):
				result9 = -1
			if (csRet.find('XLR0XG0')==-1):			
				result9 = -1
			if (result9 == -1):
				result = -1
				csRet = "pp50_check_vlanset vlan  9 checked failed."
				print  "pp50_check_vlanset     ----------"+csRet
				sys.stdout.flush()
#=========================================================
			result10 = 1
			self.hCfg.SendCmd(UART,"fswcmd show vlan  10\r","root@cnode-pp50:",10,3)
			try:
				csRet = UART.before+UART.after
			except:
				csRet = "show vlan  10 try it fail "
				result10 = -1
			print  "UART.before+UART.after:====:"+csRet
			sys.stdout.flush()
			if (csRet.find('XLR0XG1')==-1):
				result10 = -1
			if (csRet.find('FAB1X')==-1):			
				result10 = -1
			if (result10 == -1):
				result = -1
				csRet = "pp50_check_vlanset vlan  10 checked failed."
				print  "pp50_check_vlanset     ----------"+csRet
				sys.stdout.flush()

#=========================================================				
			result11 = 1
			self.hCfg.SendCmd(UART,"fswcmd show vlan  11\r","root@cnode-pp50:",10,3)
			try:
				csRet = UART.before+UART.after
			except:
				csRet = "show vlan  11 try it fail "
				result11 = -1
			print  "UART.before+UART.after:====:"+csRet
			sys.stdout.flush()
			if (csRet.find('RTMXG2')==-1):
				result11 = -1
			if (csRet.find('XLR1XG0')==-1):			
				result11 = -1
			if (result11 == -1):
				result = -1
				csRet = "pp50_check_vlanset vlan  11 checked failed."
				print  "pp50_check_vlanset     ----------"+csRet
				sys.stdout.flush()					
#=========================================================				
			result12 = 1
			self.hCfg.SendCmd(UART,"fswcmd show vlan  12\r","root@cnode-pp50:",10,3)
			try:
				csRet = UART.before+UART.after
			except:
				csRet = "show vlan  12 try it fail "
				result12 = -1
			print  "UART.before+UART.after:====:"+csRet
			sys.stdout.flush()
			if (csRet.find('XLR1XG1')==-1):
				result12 = -1
			if (csRet.find('FAB2X')==-1):			
				result12 = -1
			if (result12 == -1):
				result = -1
				csRet = "pp50_check_vlanset vlan  12 checked failed."
				print  "pp50_check_vlanset     ----------"+csRet
				sys.stdout.flush()

			if (result == -1):
				print  "FRONT 10GE VLAN is failed"
				sys.stdout.flush()
				return 0
			else:
				print  "FRONT 10GE VLAN is ok"
				sys.stdout.flush()
				return 1
#=========================================================
		if (iType==1):
			result = 1
			result9 = 1
			self.hCfg.SendCmd(UART,"fswcmd show vlan  9\r","root@cnode-pp50:",10,3)
			try:
				csRet = UART.before+UART.after
			except:
				csRet = "show vlan  9 try it fail "
				result9 = -1
			print  "UART.before+UART.after:====:"+csRet
			sys.stdout.flush()
			if (csRet.find('FPXG1')==-1):
				result9 = -1
			if (csRet.find('XLR0XG0')==-1):			
				result9 = -1
			if (result9 == -1):
				result = -1
				csRet = "pp50_check_vlanset vlan  9 checked failed."
				print  "pp50_check_vlanset     ----------"+csRet
				sys.stdout.flush()
#=========================================================
			result10 = 1
			self.hCfg.SendCmd(UART,"fswcmd show vlan  10\r","root@cnode-pp50:",10,3)
			try:
				csRet = UART.before+UART.after
			except:
				csRet = "show vlan  10 try it fail "
				result10 = -1
			print  "UART.before+UART.after:====:"+csRet
			sys.stdout.flush()
			if (csRet.find('XLR0XG1')==-1):
				result10 = -1
			if (csRet.find('FAB1X')==-1):			
				result10 = -1
			if (result10 == -1):
				result = -1
				csRet = "pp50_check_vlanset vlan  10 checked failed."
				print  "pp50_check_vlanset     ----------"+csRet
				sys.stdout.flush()

#=========================================================				
			result11 = 1
			self.hCfg.SendCmd(UART,"fswcmd show vlan  11\r","root@cnode-pp50:",10,3)
			try:
				csRet = UART.before+UART.after
			except:
				csRet = "show vlan  11 try it fail "
				result11 = -1
			print  "UART.before+UART.after:====:"+csRet
			sys.stdout.flush()
			if (csRet.find('FPXG2')==-1):
				result11 = -1
			if (csRet.find('XLR1XG0')==-1):			
				result11 = -1
			if (result11 == -1):
				result = -1
				csRet = "pp50_check_vlanset vlan  11 checked failed."
				print  "pp50_check_vlanset     ----------"+csRet
				sys.stdout.flush()					
#=========================================================				
			result12 = 1
			self.hCfg.SendCmd(UART,"fswcmd show vlan  12\r","root@cnode-pp50:",10,3)
			try:
				csRet = UART.before+UART.after
			except:
				csRet = "show vlan  12 try it fail "
				result12 = -1
			print  "UART.before+UART.after:====:"+csRet
			sys.stdout.flush()
			if (csRet.find('XLR1XG1')==-1):
				result12 = -1
			if (csRet.find('FAB2X')==-1):			
				result12 = -1
			if (result12 == -1):
				result = -1
				csRet = "pp50_check_vlanset vlan  12 checked failed."
				print  "pp50_check_vlanset     ----------"+csRet
				sys.stdout.flush()

			if (result == -1):
				print  "FRONT 10GE VLAN is failed"
				sys.stdout.flush()
				return 0
			else:
				print  "FRONT 10GE VLAN is ok"
				sys.stdout.flush()
				return 1
										
#=========================================================				
		if (iType==2):
			result = 1
			result4 = 1
			self.hCfg.SendCmd(UART,"fswcmd show vlan  4\r","root@cnode-pp50:",10,3)
			try:
				csRet = UART.before+UART.after
			except:
				csRet = "show vlan  4 try it fail "
				result4 = -1
			print  "UART.before+UART.after:====:"+csRet
			sys.stdout.flush()
			if (csRet.find('FAB1X')==-1):
				result4 = -1
			if (csRet.find('RTM1')==-1):			
				result4 = -1
			if (result4 == -1):
				result = -1
				csRet = "pp50_check_vlanset vlan  4 checked failed."
				print  "pp50_check_vlanset     ----------"+csRet
				sys.stdout.flush()
#=========================================================
			result5 = 1
			self.hCfg.SendCmd(UART,"fswcmd show vlan  5\r","root@cnode-pp50:",10,3)
			try:
				csRet = UART.before+UART.after
			except:
				csRet = "show vlan 5 try it fail "
				result5 = -1
			print  "UART.before+UART.after:====:"+csRet
			sys.stdout.flush()
			if (csRet.find('RTM2')==-1):
				result5 = -1
			if (csRet.find('RTM3')==-1):			
				result5 = -1
			if (result5 == -1):
				result = -1
				csRet = "pp50_check_vlanset vlan  5 checked failed."
				print  "pp50_check_vlanset     ----------"+csRet
				sys.stdout.flush()

#=========================================================				
			result6 = 1
			self.hCfg.SendCmd(UART,"fswcmd show vlan  6\r","root@cnode-pp50:",10,3)
			try:
				csRet = UART.before+UART.after
			except:
				csRet = "show vlan  6 try it fail "
				result6 = -1
			print  "UART.before+UART.after:====:"+csRet
			sys.stdout.flush()
			if (csRet.find('RTM4')==-1):
				result11 = -1
			if (csRet.find('RTM5')==-1):			
				result11 = -1
			if (result6 == -1):
				result = -1
				csRet = "pp50_check_vlanset vlan  6 checked failed."
				print  "pp50_check_vlanset     ----------"+csRet
				sys.stdout.flush()					
#=========================================================				
			result7 = 1
			self.hCfg.SendCmd(UART,"fswcmd show vlan  7\r","root@cnode-pp50:",10,3)
			try:
				csRet = UART.before+UART.after
			except:
				csRet = "show vlan  7  try it fail "
				result7 = -1
			print  "UART.before+UART.after:====:"+csRet
			sys.stdout.flush()
			if (csRet.find('RTM6')==-1):
				result7 = -1
			if (csRet.find('RTM7')==-1):			
				result7 = -1
			if (result7 == -1):
				result = -1
				csRet = "pp50_check_vlanset vlan  7 checked failed."
				print  "pp50_check_vlanset     ----------"+csRet
				sys.stdout.flush()
#=========================================================				
			result8 = 1
			self.hCfg.SendCmd(UART,"fswcmd show vlan  8\r","root@cnode-pp50:",10,3)
			try:
				csRet = UART.before+UART.after
			except:
				csRet = "show vlan  8  try it fail "
				result8 = -1
			print  "UART.before+UART.after:====:"+csRet
			sys.stdout.flush()
			if (csRet.find('RTM8')==-1):
				result8 = -1
			if (csRet.find('RTM9')==-1):			
				result8 = -1
			if (result8 == -1):
				result = -1
				csRet = "pp50_check_vlanset vlan  8 checked failed."
				print  "pp50_check_vlanset     ----------"+csRet
				sys.stdout.flush()
#=========================================================				
			result9 = 1
			self.hCfg.SendCmd(UART,"fswcmd show vlan  9\r","root@cnode-pp50:",10,3)
			try:
				csRet = UART.before+UART.after
			except:
				csRet = "show vlan  9  try it fail "
				result9 = -1
			print  "UART.before+UART.after:====:"+csRet
			sys.stdout.flush()
			if (csRet.find('RTM10')==-1):
				result9 = -1
			if (csRet.find('FAB2X')==-1):			
				result9 = -1
			if (result9 == -1):
				result = -1
				csRet = "pp50_check_vlanset vlan  9 checked failed."
				print  "pp50_check_vlanset     ----------"+csRet
				sys.stdout.flush()
#=========================================================				
			if (result == -1):
				print  " GE VLAN is failed"
				sys.stdout.flush()
				return 0
			else:
				print  " GE VLAN is ok"
				sys.stdout.flush()
				return 1
					
	def pp50_check_portstatusup(self,UART):
#		self.ui.info("pp50_check_portstatusup   slot:"+str(self.iSlot))
		try:
			result = 1
			UART.send("fswcmd show link all\r")
			x = UART.expect(["RTM1\s+1G\s+Enabled\s+UP", "RTM1\s+1G\s+Enabled\s+Power DOWN"], timeout = 2)
			if 1 == x:
				print  "RTM1 port status error"			
				result = 0
			x = UART.expect(["RTM2\s+1G\s+Enabled\s+UP", "RTM2\s+1G\s+Enabled\s+Power DOWN"], timeout = 2)
			if 1 == x:
				print  "RTM2 port status error"			
				result = 0

			x = UART.expect(["RTM3\s+1G\s+Enabled\s+UP", "RTM3\s+1G\s+Enabled\s+Power DOWN"], timeout = 2)
			if 1 == x:
				print  "RTM3 port status error"
				result = 0

			x = UART.expect(["RTM4\s+1G\s+Enabled\s+UP", "RTM4\s+1G\s+Enabled\s+Power DOWN"], timeout = 2)
			if 1 == x:
				print  "RTM4 port status error"
				result = 0

			x = UART.expect(["RTM5\s+1G\s+Enabled\s+UP", "RTM5\s+1G\s+Enabled\s+Power DOWN"], timeout = 2)
			if 1 == x:
				print  "RTM5 port status error"
				result = 0
			x = UART.expect(["RTM6\s+1G\s+Enabled\s+UP", "RTM6\s+1G\s+Enabled\s+Power DOWN"], timeout = 2)
			if 1 == x:
				print  "RTM6 port status error"
				result = 0

			x = UART.expect(["RTM7\s+1G\s+Enabled\s+UP", "RTM7\s+1G\s+Enabled\s+Power DOWN"], timeout = 2)
			if 1 == x:
				print  "RTM7 port status error"
				result = 0

			x = UART.expect(["RTM8\s+1G\s+Enabled\s+UP", "RTM8\s+1G\s+Enabled\s+Power DOWN"], timeout = 2)
			if 1 == x:
				print  "RTM8 port status error"
				result = 0

			x = UART.expect(["RTM9\s+1G\s+Enabled\s+UP", "RTM9\s+1G\s+Enabled\s+Power DOWN"], timeout = 2)
			if 1 == x:
				print  "RTM9 port status error"
				result = 0

			x = UART.expect(["RTM10\s+1G\s+Enabled\s+UP", "RTM10\s+1G\s+Enabled\s+Power DOWN"], timeout = 2)
			if 1 == x:		
				print  "RTM1 port status error"			
				result = 0
			if result == 0:
				return 0
			else:
				return 1
		except:
			#self.ui.info("pp50 check_ports_statusup....error")
			return 0
		
	def pp50_test_vlanset(self,UART):
		#self.ui.info("pp50_test_vlanset ")
		csScriptPath= self.hCfg.get_test_cfg("pp50_test_vlanset")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0
	def pp50_test_rtm10GE(self,UART):
		#self.ui.info("pp50_test_rtm10GE ")
		csScriptPath= self.hCfg.get_test_cfg("pp50_test_rtm10GE")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:    
			return 1
		else:
			return 0
	def pp50_test_fro10ge(self,UART):
		#self.ui.info("pp50_test_fro10ge ")
		csScriptPath= self.hCfg.get_test_cfg("pp50_test_fro10ge")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0			
	def pp50_test_GE(self,UART):
		#self.ui.info("pp50_test_fro10ge ")
		csScriptPath= self.hCfg.get_test_cfg("pp50_test_ge")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0
	def pp50_reboot(self,UART):
		#self.ui.info("pp50_reboot ")
		csScriptPath= self.hCfg.get_test_cfg("pp50_reboot")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0		
	def pp50_get_PN(self,UART):
		#self.ui.info("pp50_get_Pn")
		csScriptPath= self.hCfg.get_test_cfg("pp50_get_PN")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0
	def pp50_get_SN(self,UART):
		#self.ui.info("pp50_get_Sn ")
		csScriptPath= self.hCfg.get_test_cfg("pp50_get_SN")
		if self.hCfg.Send_ScriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0
	def	Reset_XP50(self,UART):
		x=self.hCfg.SendCmdSelector(UART,"~~.\r",["root@cnode-pp50","login"],10,2)
		if x==1:
			if self.hCfg.SendCmd(UART,"root\r","root@cnode-pp50",10,2)==1:			
				print "reset  pp50 slot.........login is ok"
				sys.stdout.flush()
			else:
				print "reset  pp50 slot.........login is error"
				sys.stdout.flush()            
				return 0
		elif x==0:
			print "reset  pp50 slot.........login is ok"
			sys.stdout.flush()
		else:
			print "reset  pp50 slot.........login is error"
			sys.stdout.flush()            
			return 0		
		self.hCfg.SendCmd(UART,"reboot\r","umount",40,2)
		print "reset  pp50 slot.....reboot....Start"
		sys.stdout.flush()
		csHint=""
		for k in  [1,10]:
			time.sleep(15)
			csHint = csHint+"+"
			print csHint
			sys.stdout.flush()

		for i in range (0,20):
			time.sleep(2)
			if self.hCfg.SendCmd(UART,"root\r","root@cnode-pp50",2,2)==1:
				break
			else:
				csProcess= "reset  pp50 slot.......runing  " +  str(i*2)
				print  csProcess
				sys.stdout.flush()
		if i>=49:
			return 0
		print "reset  pp50 slot.......end"		
		sys.stdout.flush()		
		for i in range (0,100):
			time.sleep(3)
			csProcess=" pp50 slot.....cpu....down... " +  str(i*1)
			print  csProcess
			sys.stdout.flush()
			if self.hCfg.SendCmd(UART,"halcmd\r","uv",1,2)<>1:
				csProcess= " pp50 slot ..cpu...is ..up"
				print csProcess
				sys.stdout.flush()
				break
		lcmd=["cu -l ttyS2a","cu -l ttyS4a"]
		for j in range(0,2):
			print "reset  pp50 slot........cpu......Start"
			if j==0:
				for i in range (0,50):
					time.sleep(1)
					csProcess="time " +str(j)+" pp50 slot.....cpu....runing  " +  str(i*2)
					print  csProcess
					sys.stdout.flush()
					if self.hCfg.SendCmd(UART,lcmd[j]+"\r","XP50-",1,2)==1:
						csProcess= "time " +str(j)+" pp50 slot ..cpu.....end"
						print csProcess
						sys.stdout.flush()
						break
		return 1
	def	ReloadVlan_XP50(self,UART):
		if self.hCfg.SendCmd(UART,"fswcmd reload config /etc/fswitchCfg.def\r","root@cnode-pp50",120,3)==1:        
			print"ReloadVlan_XP50 return is ok!"
			sys.stdout.flush()		
		else:
			print"ReloadVlan_XP50 return is error!"
			sys.stdout.flush()
			return 0
		time.sleep(50)
		for i in range(0,4):
			if(self.pp50_check_vlanset(UART,-1)<>-1):
				break
			else:
				print"Wait for ReloadVlan XP50 ........."
				sys.stdout.flush()
		return 1		
	def	DisablePort_XP50(self,UART):
		if self.hCfg.SendCmd(UART,"fswcmd disable port all\r","root@cnode-pp50",120,3)==1:        
			print"DisablePort_XP50 return is ok!"
			sys.stdout.flush()
			return 1				
		else:
			print"DisablePort_XP50 return is Error!"
			sys.stdout.flush()
			return 0
	def	EnablePort_XP50(self,UART):
		if self.hCfg.SendCmd(UART,"fswcmd enable port all\r","root@cnode-pp50",120,3)==1:        
			print"EnablePort_XP50 return is ok!"
			sys.stdout.flush()
			return 1				
		else:
			print"EnablePort_XP50 return is Error!"
			sys.stdout.flush()
			return 0

				
	def close_all(self):
		#self.ui.info("close all serial port")
		for i in range(1,4+1):
			serial_port = self.hCfg.get_test_cfg("XP50COM"+str(i)+"_NAME:")
			print "open Serial port  %s ...." % serial_port
			sys.stdout.flush()
			if serial_port == "NO_CFG":
				self.ui.failed("COM_NAME error")
			else:
				try:		
					UART  = pexpect.spawn('cu -l /dev/%s -s 115200 --nostop'% serial_port)
					UART.send("~.\r")
					UART.expect("Disconnected",timeout=3)
				except Exception, e:
					self.ui.failed("Close Uart Error")
				UART.__del__()
		#self.ui.info("close_all")
		return  0

	def xp50_pkgen_setting(self,UART):
		csScriptPath= self.hCfg.get_test_cfg("XP50_PKGEN_SETTING")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0

	def xp50_nfs_setting(self,UART):
		if(self.hCfg.get_test_cfg("TEST_FM40BOARD").find("ENABLE")==-1):
			csScriptPath= self.hCfg.get_test_cfg("XP50_NFS_SETTING_PHY")
		else:
			csScriptPath= self.hCfg.get_test_cfg("XP50_NFS_SETTING_CPU")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0

	def xp50_xlr0_setting(self,UART):
		if(self.hCfg.get_test_cfg("TEST_FM40BOARD").find("ENABLE")==-1):
			csScriptPath= self.hCfg.get_test_cfg("XP50_XLR0_SETTING_PHY")
		else:
			csScriptPath= self.hCfg.get_test_cfg("XP50_XLR0_SETTING_CPU")
			
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0

	def xp50_test_vlanset(self,UART):
	
	
		csScriptPath= self.hCfg.get_test_cfg("XP50_TEST_VLANSET")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0
		
	def XP50_login(self,UART):
		#self.ui.info("XP50_login")
		csScriptPath= self.hCfg.get_test_cfg("XP50_IPMC_LOGIN")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0
	def XP50_ipmc_login(self,UART):
		#self.ui.info("XP50_ipmc_login ")
		csScriptPath= self.hCfg.get_test_cfg("XP50_IPMC_LOGIN")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0
	def XP50_ipmc_logout(self,UART):
		#self.ui.info("XP50_ipmc_logout ")
		csScriptPath= self.hCfg.get_test_cfg("XP50_IPMC_LOGOUT")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0
			
	def XP50_ipmc_playload(self,UART):
		#self.ui.info("XP50_ipmc_playload ")
		csScriptPath= self.hCfg.get_test_cfg("XP50_IPMC_PLAYLOAD")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:	
			print "open Serial port  %s ...." %serial_port
			sys.stdout.flush()	
			return 1
		else:
			return 0
			
	def XP50_playload_ipmc(self,UART):
		#self.ui.info("XP50_playload_ipmc ")
		csScriptPath= self.hCfg.get_test_cfg("XP50_PLAYLOAD_IPMC")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0

	def XP501_ins_pktgen(self,UART):
		#self.ui.info("XP501_ins_pktgen ")
		csScriptPath= self.hCfg.get_test_cfg("XP501_ins_pktgen")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0	

	def XP502_ins_pktgen(self,UART):
		#self.ui.info("XP502_ins_pktgen ")
		csScriptPath= self.hCfg.get_test_cfg("XP502_ins_pktgen")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0

	def XP501_conf_pktgen(self,UART):
		#self.ui.info("XP501_conf_pktgen ")
		csScriptPath= self.hCfg.get_test_cfg("XP501_conf_pktgen")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0

	def XP502_conf_pktgen(self,UART):
		#self.ui.info("XP502_conf_pktgen ")
		csScriptPath= self.hCfg.get_test_cfg("XP502_conf_pktgen")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0

	def XP50_term_pktgen(self,UART):
		#self.ui.info("XP50_term_pktgen ")
		csScriptPath= self.hCfg.get_test_cfg("XP50_term_pktgen")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0

	def XP501_show_pktgen(self,UART):
		#self.ui.info("XP501_show_pktgen ")
		csScriptPath= self.hCfg.get_test_cfg("XP501_show_pktgen")
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0

	def XP501_start_pktgen(self,UART,csPacketSize):
		#self.ui.info("XP501_start_pktgen"+csPacketSize)
		csScriptPath= self.hCfg.get_test_cfg("XP501_start_pktgen"+csPacketSize)
		if self.hCfg.send_scriptFile(csScriptPath,UART)==1:
			return 1
		else:
			return 0		
			
#820425540 seconds from 1970 to 1996.
# end of file
